snipe-it/app/Http/Transformers/DepreciationsTransformer.php
Martin Meredith e3e0d57f56 Minor code cleanup bits and bobs (#6805)
* Add IDE Helper files

* Cleanup imports

- Alphabetises imports
- Removes unused imports

* Add Platform requirements

* Move filling asset into block where asset exists

* Remove duplicate array keys
2019-03-13 20:12:03 -07:00

44 lines
1.2 KiB
PHP

<?php
namespace App\Http\Transformers;
use App\Helpers\Helper;
use App\Models\Depreciation;
use Gate;
use Illuminate\Database\Eloquent\Collection;
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 = [
'id' => (int) $depreciation->id,
'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'] = [
'update' => Gate::allows('update', Depreciation::class) ? true : false,
'delete' => Gate::allows('delete', Depreciation::class) ? true : false,
];
$array += $permissions_array;
return $array;
}
}