laravel-datatables-fractal
laravel-datatables-fractal copied to clipboard
Datatable return same values in different pages
I am working on a project using Laravel with Mongo DB , this is my transformer
<?php
namespace App\Datatables;
use League\Fractal;
use App\Models\Device;
use Carbon\Carbon;
class DeviceTransformer extends Fractal\TransformerAbstract
{
public function transform(Device $device)
{
$online='<a ><span class="avatar"> <span class="avatar-status-offline"></span> </span>offline</a>';
$vlan= $device->InternetGatewayDevice['WANDevice']['1']['WANConnectionDevice']['1']['WANPPPConnection']['1']['X_HW_VLAN']['_value']??"";
$mac=$device->VirtualParameters['Macaddress']['_value']??"";
$pppoeUsername=$device->VirtualParameters['pppoeUsername']['_value']??"";
$rxpower=$device->VirtualParameters['RXPower']['_value']??"";
$ssid=$device->InternetGatewayDevice['LANDevice']['1']['WLANConfiguration']['1']['SSID']['_value']??"";
$lastinform=$device->_lastInform ??"";
$lastinform=Carbon::parse($lastinform)->format('Y-m-d H:i:s');
$now=Carbon::now()->subMinutes(5);
$last24hours=Carbon::now()->subHours(24);
if($lastinform> $now)
$online='<a><span class="avatar"> <span class="avatar-status-online"></span> </span>Online</a>';
elseif($lastinform<$now && $lastinform > $last24hours)
$online='<a><span class="avatar"> <span class="avatar-status-busy"></span> </span>Past 24 Hours</a>';
return [
'id' => $device->_id,
'serial'=>$device->_deviceId['_SerialNumber'],
'productclass'=>$device->_deviceId['_ProductClass'],
'vendor'=>$device->_deviceId['_Manufacturer'],
'lastInform'=> $lastinform,
'vlan' => $vlan."",
'Mac'=>$mac,
'PPPusername'=>$pppoeUsername,
'RX'=>$rxpower,
'ssid'=>$ssid,
'action'=> "<a href='".$device->_id."'>Show</a>",
'online'=>$online
];
}
}
this is how I call data in the controller
$data=Device::query();
return DataTables::of($data)
->setTransformer('App\Datatables\DeviceTransformer')
->make(true);
the problem is after 3 or 4 pages same raws comming to data table , and just 2 or 3 raws change. how is that Possible, it seems datatable return same raws again and again in different pages .