2017-07-12 17:51:22 -07:00
|
|
|
<?php
|
|
|
|
namespace App\Http\Transformers;
|
|
|
|
|
|
|
|
use App\Models\CustomField;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
use App\Helpers\Helper;
|
|
|
|
use Gate;
|
|
|
|
|
|
|
|
class CustomFieldsTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
public function transformCustomFields (Collection $fields, $total)
|
|
|
|
{
|
|
|
|
$array = array();
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
$array[] = self::transformCustomField($field);
|
|
|
|
}
|
|
|
|
return (new DatatablesTransformer)->transformDatatables($array, $total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function transformCustomField (CustomField $field)
|
|
|
|
{
|
2017-07-12 19:23:54 -07:00
|
|
|
|
2017-07-12 17:51:22 -07:00
|
|
|
$array = [
|
2018-01-17 05:31:57 -08:00
|
|
|
'id' => $field->id,
|
2017-07-25 23:40:30 -07:00
|
|
|
'name' => e($field->name),
|
|
|
|
'db_column_name' => e($field->db_column_name()),
|
|
|
|
'format' => e($field->format),
|
2017-09-18 12:29:08 -07:00
|
|
|
'required' => $field->pivot ? $field->pivot->required : false,
|
2017-07-29 17:01:03 -07:00
|
|
|
'created_at' => Helper::getFormattedDateObject($field->created_at, 'datetime'),
|
|
|
|
'updated_at' => Helper::getFormattedDateObject($field->updated_at, 'datetime'),
|
2017-07-12 17:51:22 -07:00
|
|
|
];
|
|
|
|
return $array;
|
|
|
|
}
|
2017-07-12 19:23:54 -07:00
|
|
|
|
|
|
|
|
2017-07-12 17:51:22 -07:00
|
|
|
}
|