2017-01-12 23:40:35 -08:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
|
|
|
use App\Models\Location;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
|
|
|
|
class LocationsTransformer
|
|
|
|
{
|
|
|
|
|
2017-01-26 20:07:46 -08:00
|
|
|
public function transformLocations (Collection $locations, $total)
|
2017-01-12 23:40:35 -08:00
|
|
|
{
|
2017-01-26 20:07:46 -08:00
|
|
|
$array = array();
|
|
|
|
foreach ($locations as $location) {
|
|
|
|
$array[] = self::transformLocation($location);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
2017-01-12 23:40:35 -08:00
|
|
|
}
|
|
|
|
|
2017-01-13 01:45:14 -08:00
|
|
|
public function transformLocation (Location $location = null)
|
2017-01-12 23:40:35 -08:00
|
|
|
{
|
|
|
|
if ($location) {
|
2017-01-24 21:04:38 -08:00
|
|
|
$transformed = [
|
2017-01-12 23:40:35 -08:00
|
|
|
'id' => e($location->id),
|
2017-01-13 00:13:57 -08:00
|
|
|
'name' => e($location->name),
|
|
|
|
'address' => e($location->address),
|
|
|
|
'city' => e($location->city),
|
|
|
|
'state' => e($location->state),
|
2017-01-26 20:07:46 -08:00
|
|
|
'assets_checkedout' => $location->assets()->count(),
|
|
|
|
'assets_default' => $location->assignedassets()->count(),
|
2017-01-13 00:13:57 -08:00
|
|
|
'country' => e($location->country),
|
2017-01-12 23:40:35 -08:00
|
|
|
];
|
2017-01-24 21:04:38 -08:00
|
|
|
return $transformed;
|
2017-01-12 23:40:35 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|