|
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
|
|
|
public function index() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->authorize('view'); |
|
23
|
|
|
$trainingtypes = TrainingType::orderBy('name')->get(); |
|
24
|
|
|
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
|
|
|
public function create() |
|
33
|
|
|
{ |
|
34
|
|
|
$this->authorize('edit'); |
|
35
|
|
|
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
|
|
|
public function store(StoreTrainingTypeRequest $request) |
|
45
|
|
|
{ |
|
46
|
|
|
$trainingtype = TrainingType::create($request->all()); |
|
|
|
|
|
|
47
|
|
|
Notification::container()->success('Training Type Created'); |
|
48
|
|
|
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
|
|
|
public function show($trainingtypeId) |
|
58
|
|
|
{ |
|
59
|
|
|
$this->authorize('view'); |
|
60
|
|
|
$trainingtype = TrainingType::find($trainingtypeId); |
|
61
|
|
|
$trainings = $trainingtype->trainings; |
|
62
|
|
|
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
|
|
|
public function edit(TrainingType $trainingtype) |
|
72
|
|
|
{ |
|
73
|
|
|
$this->authorize('edit'); |
|
74
|
|
|
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
|
|
View Code Duplication |
public function update(StoreTrainingTypeRequest $request, TrainingType $trainingtype) |
|
85
|
|
|
{ |
|
86
|
|
|
$this->authorize('edit'); |
|
87
|
|
|
$data = $request->all(); |
|
88
|
|
|
$trainingtype->update($data); |
|
89
|
|
|
Notification::container()->success('Training Type Updated'); |
|
90
|
|
|
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
|
|
|
public function destroy($id) |
|
100
|
|
|
{ |
|
101
|
|
|
$this->authorize('edit'); |
|
102
|
|
|
$trainingtype = TrainingType::findOrFail($id); |
|
103
|
|
|
$trainingtype->trainings()->update(['training_type_id'=>null]); |
|
104
|
|
|
$trainingtype->delete(); |
|
105
|
|
|
} |
|
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
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.