File tree Expand file tree Collapse file tree 2 files changed +43
-2
lines changed
Expand file tree Collapse file tree 2 files changed +43
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Laravel \DataTables \Resources ;
4+
5+ use Illuminate \Support \Arr ;
6+ use Illuminate \Http \Resources \Json \JsonResource ;
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 $collection
18+ */
19+ public function rejectNullValues ($ collection )
20+ {
21+ return array_filter ($ collection , fn ($ resource ) => !is_null ($ resource ) || !empty ($ resource ));
22+ }
23+
24+ /**
25+ * @param $request
26+ */
27+ /**
28+ * @param $request
29+ */
30+ public function toArray ($ request )
31+ {
32+
33+ return [
34+ 'id ' => $ this ->id ,
35+ 'created_at_human ' => optional ($ this ->created_at )->diffForHumans (),
36+ 'updated_at_human ' => optional ($ this ->updated_at )->diffForHumans (),
37+ ] + Arr::only (
38+ $ this ->resource ->toArray (), $ this ->dataTable ()->getDisplayableColumns ()
39+ );
40+ }
41+ }
Original file line number Diff line number Diff line change 11<?php
2- namespace Laravel \Datatables \Services ;
2+ namespace Laravel \DataTables \Services ;
33
44use Arr ;
55use Schema ;
1111use Laravel \DataTables \Contracts \Displayable ;
1212use Laravel \DataTables \Exceptions \EloquentBuilderWasSetToNullException ;
1313
14- abstract class BaseDatatableService implements Displayable
14+ abstract class BaseDataTableService implements Displayable
1515{
1616 use Macroable;
1717
You can’t perform that action at this time.
0 commit comments