File tree 2 files changed +43
-2
lines changed
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 1
1
<?php
2
- namespace Laravel \Datatables \Services ;
2
+ namespace Laravel \DataTables \Services ;
3
3
4
4
use Arr ;
5
5
use Schema ;
11
11
use Laravel \DataTables \Contracts \Displayable ;
12
12
use Laravel \DataTables \Exceptions \EloquentBuilderWasSetToNullException ;
13
13
14
- abstract class BaseDatatableService implements Displayable
14
+ abstract class BaseDataTableService implements Displayable
15
15
{
16
16
use Macroable;
17
17
You can’t perform that action at this time.
0 commit comments