1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\SensorData; |
6
|
|
|
use App\DataTables\SensorDataDataTable; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
|
9
|
|
|
class SensorDataController extends Controller |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Create a new controller instance. |
13
|
|
|
* |
14
|
|
|
* @return void |
15
|
|
|
*/ |
16
|
|
|
public function __construct() |
17
|
|
|
{ |
18
|
|
|
$this->middleware('auth'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Display a listing of the resource. |
23
|
|
|
* |
24
|
|
|
* @param SensorDataDataTable $dataTable |
25
|
|
|
* @return Response |
|
|
|
|
26
|
|
|
*/ |
27
|
|
|
public function index(SensorDataDataTable $dataTable) |
28
|
|
|
{ |
29
|
|
|
$this->authorize('index', SensorData::class); |
30
|
|
|
|
31
|
|
|
return $dataTable->render('sensordata.index'); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Show the form for creating a new resource. |
36
|
|
|
* |
37
|
|
|
* @return Response |
38
|
|
|
*/ |
39
|
|
|
public function create() |
40
|
|
|
{ |
41
|
|
|
$this->authorize('create', SensorData::class); |
42
|
|
|
|
43
|
|
|
return view('sensordata.create'); |
|
|
|
|
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Store a newly created resource in storage. |
48
|
|
|
* |
49
|
|
|
* @param Request $request |
50
|
|
|
* @return Response |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function store(Request $request) |
53
|
|
|
{ |
54
|
|
|
$this->authorize('store', SensorData::class); |
55
|
|
|
|
56
|
|
|
request()->validate([ |
57
|
|
|
'sensor_id' => 'required|integer|digits_between:1,10|exists:sensors,id', |
58
|
|
|
'value' => 'required|max:190|value_string' |
59
|
|
|
]); |
60
|
|
|
|
61
|
|
|
$sensorData = SensorData::create($request->all()); |
62
|
|
|
|
63
|
|
|
return redirect()->route('sensordata.show', $sensorData->id) |
|
|
|
|
64
|
|
|
->with('success', 'SensorData created successfully'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Display the specified resource. |
69
|
|
|
* |
70
|
|
|
* @param String $id |
71
|
|
|
* @return Response |
72
|
|
|
*/ |
73
|
|
View Code Duplication |
public function show($id) |
74
|
|
|
{ |
75
|
|
|
$this->authorize('show', SensorData::class); |
76
|
|
|
|
77
|
|
|
$sensorData = SensorData::findOrFail($id); |
78
|
|
|
return view('sensordata.show', [ 'sensordata' => $sensorData ]); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Show the form for editing the specified resource. |
83
|
|
|
* |
84
|
|
|
* @param String $id |
85
|
|
|
* @return Response |
86
|
|
|
*/ |
87
|
|
View Code Duplication |
public function edit($id) |
88
|
|
|
{ |
89
|
|
|
$this->authorize('edit', SensorData::class); |
90
|
|
|
|
91
|
|
|
$sensorData = SensorData::findOrFail($id); |
92
|
|
|
return view('sensordata.edit', [ 'sensordata' => $sensorData ]); |
|
|
|
|
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Update the specified resource in storage. |
97
|
|
|
* |
98
|
|
|
* @param Request $request |
99
|
|
|
* @param String $id |
100
|
|
|
* @return Response |
101
|
|
|
*/ |
102
|
|
|
public function update(Request $request, $id) |
103
|
|
|
{ |
104
|
|
|
$this->authorize('update', SensorData::class); |
105
|
|
|
|
106
|
|
|
request()->validate([ |
107
|
|
|
'sensor_id' => 'required|integer|digits_between:1,10|exists:sensors,id', |
108
|
|
|
'value' => 'required|max:190|value_string' |
109
|
|
|
]); |
110
|
|
|
$query = SensorData::findOrFail($id)->update($request->all()); |
|
|
|
|
111
|
|
|
return redirect()->route('sensordata.show', $id) |
|
|
|
|
112
|
|
|
->with('success', 'SensorData updated successfully'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Remove the specified resource from storage. |
117
|
|
|
* |
118
|
|
|
* @param String $id |
119
|
|
|
* @return Response |
120
|
|
|
*/ |
121
|
|
|
public function destroy($id) |
122
|
|
|
{ |
123
|
|
|
$this->authorize('destroy', SensorData::class); |
124
|
|
|
|
125
|
|
|
SensorData::findOrFail($id)->delete(); |
126
|
|
|
return redirect()->route('sensordata.index') |
|
|
|
|
127
|
|
|
->with('success', 'SensorData deleted successfully'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|