2017-03-11 08:03:16 -08:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
2019-03-13 20:12:03 -07:00
|
|
|
use App\Helpers\Helper;
|
2017-03-11 08:03:16 -08:00
|
|
|
use App\Models\Depreciation;
|
|
|
|
use Gate;
|
2019-03-13 20:12:03 -07:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2017-03-11 08:03:16 -08:00
|
|
|
|
|
|
|
class DepreciationsTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
public function transformDepreciations (Collection $depreciations)
|
|
|
|
{
|
|
|
|
$array = array();
|
|
|
|
foreach ($depreciations as $depreciation) {
|
|
|
|
$array[] = self::transformDepreciation($depreciation);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transformDepreciation (Depreciation $depreciation)
|
|
|
|
{
|
|
|
|
$array = [
|
2017-07-25 23:40:30 -07:00
|
|
|
'id' => (int) $depreciation->id,
|
2017-03-11 08:03:16 -08:00
|
|
|
'name' => e($depreciation->name),
|
|
|
|
'months' => $depreciation->months . ' '. trans('general.months'),
|
|
|
|
'created_at' => Helper::getFormattedDateObject($depreciation->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($depreciation->updated_at, 'datetime'),
|
|
|
|
];
|
|
|
|
|
|
|
|
$permissions_array['available_actions'] = [
|
2020-05-23 10:36:02 -07:00
|
|
|
'update' => Gate::allows('update', Depreciation::class),
|
|
|
|
'delete' => Gate::allows('delete', Depreciation::class),
|
2017-03-11 08:03:16 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
$array += $permissions_array;
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|