| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * UsersDataTable.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Provide layout and data for the Users DataTable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * This program is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * it under the terms of the GNU General Public License as published by | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * GNU General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * You should have received a copy of the GNU General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @package    LibreNMS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @link       http://librenms.org | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @copyright  2016 Tony Murray | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @author     Tony Murray <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | namespace App\DataTables\General; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use App\DataTables\BaseDataTable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | use App\Models\User; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  | class UserDataTable extends BaseDataTable | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      * Display ajax response. | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     public function ajax() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         return $this->datatables | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             ->eloquent($this->query()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             ->editColumn('level', function($user) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 return trans('user.level.'.$user->level); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |             ->editColumn('actions', function($user) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                 $edit = '<a type="button" class="btn btn-xs btn-primary" href="'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                     route('users.edit', ['user_id' => $user->user_id]). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                     '"><i class="fa fa-edit fa-lg fa-fw"></i><span class="hidden-xs"> Edit</span></a> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                 $delete = '<button type="button" class="btn btn-xs btn-danger userDeleteModal" data-toggle="modal" data-target="#deleteModal" data-href="'. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                     route('users.destroy', ['user_id' => $user->user_id]). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                     '"><i class="fa fa-trash fa-lg fa-fw"></i><span class="hidden-xs"> Delete</span></button> '; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 return $edit.$delete; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             }) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |             ->make(true); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * Get the query object to be processed by datatables. | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     public function query() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $users = User::select('users.*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         return $this->applyScopes($users); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |      * Get columns. | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     public function getColumns() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             'username' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                 'title' => trans('user.text.username'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |             'realname' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                 'title' => trans('user.text.realname'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             'level'    => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                 'title' => trans('user.text.level'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             'actions'  => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 'title' => trans('user.text.actions'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         ]; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 91 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |      * Get filename for export. | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     protected function filename() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         return 'users'; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 102 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 103 |  |  |  | 
            
                        
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: