| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * app/DataTables/DeviceDataTable.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * Datatable for devices | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 Neil Lathwood | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @author     Neil Lathwood <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | namespace App\DataTables; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use App\Models\Device; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | class DeviceDataTable extends BaseDataTable | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * Display ajax response. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     public function ajax() | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         return $this->datatables | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |             ->eloquent($this->query()) | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |             ->editColumn('status_reason', function($device) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |                 if ($device->status == 0) | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |                 { | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |                     return '<span data-toggle="tooltip" title="down" class="badge bg-red">'.$device->status_reason.'</span>'; | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |                 else | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |                 { | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |                     return '<span data-toggle="tooltip" title="up" class="badge bg-light-blue">up</span>'; | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |             }) | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             ->editColumn('vendor', function($device) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                 return '<img src="'.$device->logo().'" border="0" alt="'.$device->os.'">'; | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |             }) | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             ->editColumn('hostname', function($device) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |                 $hostname = is_null($device) ? trans('devices.text.deleted') : $device->hostname; | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |                 return '<a href="'.url("devices/".$device->device_id).'">'.$hostname.'</a>'; | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |             }) | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |             ->editColumn('resources', function($device) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |                 $ports   = $device->ports()->count(); | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |                 $sensors = $device->sensors()->count(); | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |                 return '<span data-toggle="tooltip" title="'.$ports.' Ports" class="badge bg-light-blue"><i class="fa fa-link"></i>  '.$ports.'</span><br /> | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |                         <span data-toggle="tooltip" title="'.$sensors.' Sensors" class="badge bg-light-blue"><i class="fa fa-dashboard"></i>  '.$sensors.'</span>'; | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |             }) | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |             ->editColumn('hardware', function($device) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |                 return $device->hardware.'<br />'.$device->features; | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |             }) | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |             ->editColumn('os', function($device) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |                 return ucfirst($device->os).'<br />'.$device->version; | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |             }) | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |             ->editColumn('location', function($device) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |                 return $device->formatUptime($device->uptime).'<br />'.$device->location; | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |             }) | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |             ->make(true); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * Get the query object to be processed by datatables. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      * @return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     public function query() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $device = Device::select('devices.*'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         return $this->applyScopes($device); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * Get columns. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     public function getColumns() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |             'status'    => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |                 'title' => trans('general.text.status'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |                 'data'  => 'status_reason', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |                 'width' => '40px', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             'vendor'        => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |                 'title' => trans('devices.text.vendor'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |                 'width' => '20px', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |             'hostname'  => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |                 'title' => trans('devices.label.hostname'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             'resources'  => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |                 'title'  => '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                 'search' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             'hardware'  => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                 'title' => trans('devices.text.platform'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             'features'    => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                 'visible' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             'os'        => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |                 'title' => trans('devices.text.os'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |             'version'     => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                 'visible' => false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |             'location'  => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                 'title' => trans('devices.text.uptime_location'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |      * Get filename for export. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |     protected function filename() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         return 'devices'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 138 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 139 |  |  |  | 
            
                        
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: