|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\Holidays; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
|
|
8
|
|
|
use App\Http\Requests; |
|
9
|
|
|
use App\Http\Controllers\Controller; |
|
10
|
|
|
|
|
11
|
|
|
class HolidaysController extends Controller |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* HolidaysController constructor. |
|
15
|
|
|
*/ |
|
16
|
|
|
public function __construct() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->middleware('lang'); |
|
19
|
|
|
$this->middleware('auth'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Display a listing of the resource. |
|
24
|
|
|
* |
|
25
|
|
|
* @return \Illuminate\Http\Response |
|
26
|
|
|
*/ |
|
27
|
|
|
public function index() |
|
28
|
|
|
{ |
|
29
|
|
|
$data['query'] = Holidays::all(); |
|
|
|
|
|
|
30
|
|
|
return view('holidays/list', $data); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Show the form for creating a new resource. |
|
35
|
|
|
* |
|
36
|
|
|
* @return \Illuminate\Http\Response |
|
37
|
|
|
*/ |
|
38
|
|
|
public function create() |
|
39
|
|
|
{ |
|
40
|
|
|
return view('holidays/request'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Store a newly created resource in storage. |
|
45
|
|
|
* |
|
46
|
|
|
* @param Requests\HolidayValidator $input |
|
47
|
|
|
* @return \Illuminate\Http\Response |
|
48
|
|
|
*/ |
|
49
|
|
|
public function store(Requests\HolidayValidator $input) |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
$holiday = new Holidays(); |
|
52
|
|
|
$holiday->user_id = auth()->user()->id; |
|
|
|
|
|
|
53
|
|
|
$holiday->type = ''; |
|
|
|
|
|
|
54
|
|
|
$holiday->from = ''; |
|
|
|
|
|
|
55
|
|
|
$holiday->until = ''; |
|
|
|
|
|
|
56
|
|
|
$holiday->description = ''; |
|
|
|
|
|
|
57
|
|
|
$holiday->save(); |
|
58
|
|
|
|
|
59
|
|
|
session()->flash('message', ''); |
|
60
|
|
|
return redirect()->back(); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Display the specified resource. |
|
65
|
|
|
* |
|
66
|
|
|
* @param int $id |
|
67
|
|
|
* @return \Illuminate\Http\Response |
|
68
|
|
|
*/ |
|
69
|
|
|
public function show($id) |
|
70
|
|
|
{ |
|
71
|
|
|
$data['query'] = Holidays::with('users')->where('id', $id)->get(); |
|
|
|
|
|
|
72
|
|
|
return view('', $data); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Show the form for editing the specified resource. |
|
77
|
|
|
* |
|
78
|
|
|
* @param int | $id | The database id. |
|
79
|
|
|
* @return \Illuminate\Http\Response |
|
80
|
|
|
*/ |
|
81
|
|
|
public function edit($id) |
|
82
|
|
|
{ |
|
83
|
|
|
$data['query'] = Holidays::find($id); |
|
|
|
|
|
|
84
|
|
|
return view('', $data); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Update the specified resource in storage. |
|
89
|
|
|
* |
|
90
|
|
|
* @param Requests\HolidayValidator $input |
|
91
|
|
|
* @param int | $id | The database id. |
|
92
|
|
|
* @return \Illuminate\Http\Response |
|
93
|
|
|
*/ |
|
94
|
|
|
public function update(Requests\HolidayValidator $input, $id) |
|
|
|
|
|
|
95
|
|
|
{ |
|
96
|
|
|
Holidays::find($id)->update([ |
|
97
|
|
|
'user_id' => auth()->user()->id |
|
|
|
|
|
|
98
|
|
|
]); |
|
99
|
|
|
|
|
100
|
|
|
session()->flash('message', ''); |
|
101
|
|
|
return redirect()->back(302); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Remove the specified resource from storage. |
|
106
|
|
|
* |
|
107
|
|
|
* @param int | $id | The database id. |
|
108
|
|
|
* @return \Illuminate\Http\Response |
|
109
|
|
|
*/ |
|
110
|
|
|
public function destroy($id) |
|
111
|
|
|
{ |
|
112
|
|
|
Holidays::destroy($id); |
|
113
|
|
|
session()->flash('message', 'Vacation request deleted.'); |
|
114
|
|
|
return redirect()->back(302); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.