| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\DataTables; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use App\User; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Yajra\DataTables\Services\DataTable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Spatie\Activitylog\Models\Activity; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class ActivityLogDataTable extends DataTable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      * Build DataTable class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * @return \Yajra\DataTables\DataTableAbstract | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     public function dataTable($query) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         return datatables($query) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |             ->editColumn('causer_id', function ($activity) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |                 if ($activity->causer_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |                     return '<a href="/' . ($activity->causer_type == "App\User" ? 'user' : 'device') . '/' . $activity->causer_id . '">' . $activity->causer->name . '</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |                     return 'Application'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             ->editColumn('subject_id', function ($activity) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |                 if ($activity->subject_id) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |                     return '<a href="/' . ($activity->subject_type == "App\User" ? 'user' : 'device') . '/' . $activity->subject_id . '">' . $activity->subject->name . '</a>'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                     return 'None'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |             }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             ->editColumn('properties', function ($activity) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                 return $activity->properties; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             ->rawColumns(['causer_id', 'subject_id', 'properties']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * Get query source of dataTable. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @return \Illuminate\Database\Eloquent\Builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     public function query() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         $query = Activity::query(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         return $this->applyScopes($query); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * Optional method if you want to use html builder. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @return \Yajra\DataTables\Html\Builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public function html() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         return $this->builder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             ->columns($this->getColumns()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |             ->minifiedAjax() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |             ->parameters($this->getBuilderParameters()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * Get columns. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     protected function getColumns() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             'created_at', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             [ 'name' => 'causer_id', 'data' => 'causer_id', 'title' => 'Actor', 'render' => null, 'searchable' => true, 'orderable' => true, 'exportable' => true, 'printable' => true, 'footer' => '' ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             [ 'name' => 'description', 'data' => 'description', 'title' => 'Action', 'render' => null, 'searchable' => true, 'orderable' => true, 'exportable' => true, 'printable' => true, 'footer' => '' ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             [ 'name' => 'subject_id', 'data' => 'subject_id', 'title' => 'Subject', 'render' => null, 'searchable' => true, 'orderable' => true, 'exportable' => true, 'printable' => true, 'footer' => '' ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |             [ 'name' => 'properties', 'data' => 'properties', 'title' => 'Changes', 'render' => null, 'searchable' => true, 'orderable' => false, 'exportable' => true, 'printable' => true, 'footer' => '' ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      * Get builder parameters. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     protected function getBuilderParameters() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             'dom'     => 'Bfrtip', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             'order'   => [ [ 0, 'desc' ] ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             'buttons' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                 'export', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 'print', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |                 'reset', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |                 'reload', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             'paging' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             'searching' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             'info' => true, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |             'searchDelay' => 500, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |      * Get filename for export. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 107 |  |  |     protected function filename() | 
            
                                                        
            
                                    
            
            
                | 108 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 109 |  |  |         return 'activitylog_' . time(); | 
            
                                                        
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 111 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |  | 
            
                        
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: