1 | <?php |
||
2 | |||
3 | namespace Laravel\DataTables\Resources; |
||
4 | |||
5 | use Illuminate\Http\Resources\Json\JsonResource; |
||
6 | use Illuminate\Support\Arr; |
||
7 | use Laravel\DataTables\Services\BaseDataTableService; |
||
8 | |||
9 | abstract class BaseResource extends JsonResource |
||
10 | { |
||
11 | /** |
||
12 | * @param BaseDatatableService $dataTable |
||
13 | */ |
||
14 | abstract public function dataTable(): BaseDataTableService; |
||
15 | |||
16 | /** |
||
17 | * @param $resource |
||
18 | */ |
||
19 | public function rejectNullValues($resource) |
||
20 | { |
||
21 | return array_filter($resource, function ($value) { |
||
22 | return ! is_null($value) || ! empty($value); |
||
23 | }); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * @param $request |
||
28 | */ |
||
29 | |||
30 | /** |
||
31 | * @param $request |
||
32 | */ |
||
33 | public function toArray($request) |
||
34 | { |
||
35 | return $this->rejectNullValues([ |
||
36 | 'id' => $this->id, |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
37 | 'created_at_human' => optional($this->created_at)->diffForHumans(), |
||
0 ignored issues
–
show
The property
created_at does not exist on Laravel\DataTables\Resources\BaseResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
38 | 'updated_at_human' => optional($this->updated_at)->diffForHumans(), |
||
0 ignored issues
–
show
The property
updated_at does not exist on Laravel\DataTables\Resources\BaseResource . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
39 | ] + Arr::only( |
||
40 | $this->resource->toArray(), |
||
41 | $this->dataTable()->getDisplayableColumns() |
||
42 | )); |
||
43 | } |
||
44 | } |
||
45 |