1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SET\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Illuminate\Support\Facades\Auth; |
7
|
|
|
use Illuminate\Support\Facades\Input; |
8
|
|
|
use Krucas\Notification\Facades\Notification; |
9
|
|
|
use SET\Http\Controllers\Controller; |
10
|
|
|
use SET\Http\Requests\StoreTrainingTypeRequest; |
11
|
|
|
use SET\TrainingType; |
12
|
|
|
|
13
|
|
|
class TrainingTypeController extends Controller |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Display a listing of the resource. |
17
|
|
|
* |
18
|
|
|
* @return \Illuminate\Http\Response |
19
|
|
|
*/ |
20
|
1 |
|
public function index() |
21
|
|
|
{ |
22
|
1 |
|
$this->authorize('view'); |
23
|
1 |
|
$trainingtypes = TrainingType::orderBy('name')->get(); |
24
|
1 |
|
return view('trainingtype.index', compact('trainingtypes')); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Show the form for creating a new resource. |
29
|
|
|
* |
30
|
|
|
* @return \Illuminate\Http\Response |
31
|
|
|
*/ |
32
|
1 |
|
public function create() |
33
|
|
|
{ |
34
|
1 |
|
$this->authorize('edit'); |
35
|
1 |
|
return view('trainingtype.create'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Store a newly created resource in storage. |
40
|
|
|
* |
41
|
|
|
* @param StoreTrainingTypeRequest $request |
42
|
|
|
* @return \Illuminate\Http\Response |
43
|
|
|
*/ |
44
|
2 |
|
public function store(StoreTrainingTypeRequest $request) |
45
|
|
|
{ |
46
|
2 |
|
$trainingtype = TrainingType::create($request->all()); |
|
|
|
|
47
|
2 |
|
Notification::container()->success('Training Type Created'); |
48
|
2 |
|
return redirect()->action('TrainingTypeController@index'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Show the individual training type record. |
53
|
|
|
* |
54
|
|
|
* @param $trainingtypeId |
55
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
56
|
|
|
*/ |
57
|
1 |
|
public function show($trainingtypeId) |
58
|
|
|
{ |
59
|
1 |
|
$this->authorize('view'); |
60
|
1 |
|
$trainingtype = TrainingType::find($trainingtypeId); |
61
|
1 |
|
$trainings = $trainingtype->trainings; |
62
|
1 |
|
return view('trainingtype.show', compact('trainingtype', 'trainings')); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Show the form for editing the specified resource. |
67
|
|
|
* |
68
|
|
|
* @param int $id |
|
|
|
|
69
|
|
|
* @return \Illuminate\Http\Response |
70
|
|
|
*/ |
71
|
1 |
|
public function edit(TrainingType $trainingtype) |
72
|
|
|
{ |
73
|
1 |
|
$this->authorize('edit'); |
74
|
1 |
|
return view('trainingtype.edit', compact('trainingtype')); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Update the specified resource in storage. |
79
|
|
|
* |
80
|
|
|
* @param \Illuminate\Http\Request $request |
81
|
|
|
* @param int $id |
|
|
|
|
82
|
|
|
* @return \Illuminate\Http\Response |
83
|
|
|
*/ |
84
|
2 |
View Code Duplication |
public function update(StoreTrainingTypeRequest $request, TrainingType $trainingtype) |
85
|
|
|
{ |
86
|
2 |
|
$this->authorize('edit'); |
87
|
2 |
|
$data = $request->all(); |
88
|
2 |
|
$trainingtype->update($data); |
89
|
2 |
|
Notification::container()->success('Training Type Updated'); |
90
|
2 |
|
return redirect()->action('TrainingTypeController@show', $trainingtype->id); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Remove the specified resource from storage. |
95
|
|
|
* |
96
|
|
|
* @param int $id |
97
|
|
|
* @return \Illuminate\Http\Response |
98
|
|
|
*/ |
99
|
3 |
|
public function destroy($id) |
100
|
|
|
{ |
101
|
3 |
|
$this->authorize('edit'); |
102
|
3 |
|
$trainingtype = TrainingType::findOrFail($id); |
103
|
3 |
|
$trainingtype->trainings()->update(['training_type_id'=>null]); |
104
|
3 |
|
$trainingtype->delete(); |
105
|
3 |
|
} |
106
|
|
|
} |
107
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.