1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\DataTables; |
4
|
|
|
|
5
|
|
|
use Yajra\DataTables\Services\DataTable; |
6
|
|
|
use App\SensorData; |
7
|
|
|
|
8
|
|
|
class SensorDataDataTable extends DataTable |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Build DataTable class. |
12
|
|
|
* |
13
|
|
|
* @return \Yajra\DataTables\Engines\BaseEngine |
|
|
|
|
14
|
|
|
*/ |
15
|
|
|
public function dataTable($query) |
16
|
|
|
{ |
17
|
|
|
return datatables($query) |
18
|
|
|
->addColumn('sensor', function($sensordata) { |
19
|
|
|
return '<a href="'.route('sensor.show', $sensordata->sensor_id).'">'.($sensordata->sensor->name ?? 'null').'</a>'; |
20
|
|
|
}) |
21
|
|
|
->addColumn('device', function($sensordata) { |
22
|
|
|
return '<a href="'.route('device.show', $sensordata->sensor->device->id ?? '0').'">'.($sensordata->sensor->device->name ?? 'null').'</a>'; |
|
|
|
|
23
|
|
|
}) |
24
|
|
|
->addColumn('action', 'sensordata.action') |
25
|
|
|
->blacklist([ 'action' ]) |
26
|
|
|
->rawColumns([ 'device', 'sensor', 'action' ]); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Get the query object to be processed by dataTables. |
31
|
|
|
* |
32
|
|
|
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection |
33
|
|
|
*/ |
34
|
|
|
public function query() |
35
|
|
|
{ |
36
|
|
|
$query = SensorData::query(); |
37
|
|
|
return $this->applyScopes($query); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Optional method if you want to use html builder. |
42
|
|
|
* |
43
|
|
|
* @return \Yajra\DataTables\Html\Builder |
44
|
|
|
*/ |
45
|
|
|
public function html() |
46
|
|
|
{ |
47
|
|
|
return $this->builder() |
48
|
|
|
->columns($this->getColumns()) |
49
|
|
|
->minifiedAjax() |
50
|
|
|
->parameters($this->getBuilderParameters()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get columns. |
55
|
|
|
* |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
|
|
protected function getColumns() |
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
'id', |
62
|
|
|
[ 'data' => 'sensor', 'name' => 'sensors.id', 'title' => 'Sensor', 'searchable' => false ], |
63
|
|
|
[ 'data' => 'device', 'name' => 'devices.id', 'title' => 'Device', 'searchable' => false ], |
64
|
|
|
'value', |
65
|
|
|
'created_at', |
66
|
|
|
'updated_at', |
67
|
|
|
[ 'data' => 'action', 'name' => 'action', 'title' => 'Action', 'searchable' => false, 'orderable' => false, 'exportable' => false, 'printable' => false ] |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get builder parameters. |
73
|
|
|
* |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
View Code Duplication |
protected function getBuilderParameters() |
77
|
|
|
{ |
78
|
|
|
return [ |
79
|
|
|
'dom' => 'Bfrtip', |
80
|
|
|
'order' => [ [ 0, 'desc' ] ], |
81
|
|
|
'buttons' => [ |
82
|
|
|
'create', |
83
|
|
|
[ 'extend' => 'collection', 'text' => '<i class="fa fa-file-excel-o"></i> Export', 'buttons' => [ |
84
|
|
|
[ 'extend' => 'csv', 'exportOptions' => [ 'modifier' => [ 'search' => true ] ] ], |
85
|
|
|
[ 'extend' => 'excel', 'exportOptions' => [ 'modifier' => [ 'search' => true ] ] ], |
86
|
|
|
] ], |
87
|
|
|
[ 'extend' => 'print', 'exportOptions' => [ 'modifier' => [ 'search' => true ] ] ], |
88
|
|
|
'reset', |
89
|
|
|
'reload', |
90
|
|
|
], |
91
|
|
|
'paging' => true, |
92
|
|
|
'searching' => true, |
93
|
|
|
'info' => true, |
94
|
|
|
'searchDelay' => 500, |
95
|
|
|
]; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Get filename for export. |
100
|
|
|
* |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
protected function filename() |
104
|
|
|
{ |
105
|
|
|
return 'sensordata_'.time(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths