|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use App\TasksRequest; |
|
6
|
|
|
use Illuminate\Http\Request; |
|
7
|
|
|
use App\Http\Requests; |
|
8
|
|
|
use App\Http\Controllers\Controller; |
|
9
|
|
|
|
|
10
|
|
|
use App\User; |
|
11
|
|
|
use App\Tasks; |
|
12
|
|
|
|
|
13
|
|
|
class TaskController extends Controller |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* TaskController constructor. |
|
17
|
|
|
*/ |
|
18
|
|
|
public function __construct() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->middleware('auth'); |
|
21
|
|
|
$this->middleware('lang'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Display a listing of the resource. |
|
26
|
|
|
* |
|
27
|
|
|
* @return \Illuminate\Http\Response |
|
28
|
|
|
*/ |
|
29
|
|
|
public function index() |
|
30
|
|
|
{ |
|
31
|
|
|
$data['tasks'] = TasksRequest::paginate(15); |
|
|
|
|
|
|
32
|
|
|
return view("tasks.manage_tasks", $data); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Show the form for creating a new resource. |
|
37
|
|
|
* |
|
38
|
|
|
* @return \Illuminate\Http\Response |
|
39
|
|
|
*/ |
|
40
|
|
|
public function create() |
|
41
|
|
|
{ |
|
42
|
|
|
$data['users'] = User::all(); |
|
|
|
|
|
|
43
|
|
|
$data['tasks'] = Tasks::all(); |
|
44
|
|
|
|
|
45
|
|
|
return view("tasks.request_task", $data); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Store a newly created resource in storage. |
|
50
|
|
|
* |
|
51
|
|
|
* @param Requests\taskRequestValidator $request |
|
52
|
|
|
* @return \Illuminate\Http\Response |
|
53
|
|
|
*/ |
|
54
|
|
|
public function store(Requests\taskRequestValidator $request) |
|
|
|
|
|
|
55
|
|
|
{ |
|
56
|
|
|
// |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Display the specified resource. |
|
61
|
|
|
* |
|
62
|
|
|
* @param int $id, The id off the task in the database. |
|
|
|
|
|
|
63
|
|
|
* @return \Illuminate\Http\Response |
|
64
|
|
|
*/ |
|
65
|
|
|
public function show($id) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
// |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Show the form for editing the specified resource. |
|
72
|
|
|
* |
|
73
|
|
|
* @param int $id The id off the task in the database. |
|
74
|
|
|
* @return \Illuminate\Http\Response |
|
75
|
|
|
*/ |
|
76
|
|
|
public function edit($id) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
// |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Update the specified resource in storage. |
|
83
|
|
|
* |
|
84
|
|
|
* @param Requests\taskValidator $request |
|
85
|
|
|
* @param int $id, the task request id. |
|
|
|
|
|
|
86
|
|
|
* @return \Illuminate\Http\Response |
|
87
|
|
|
*/ |
|
88
|
|
|
public function update(Requests\taskValidator $request, $id) |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
// |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Remove the specified resource from storage. |
|
95
|
|
|
* |
|
96
|
|
|
* @param Request $request |
|
97
|
|
|
* @return \Illuminate\Http\Response |
|
98
|
|
|
*/ |
|
99
|
|
|
public function destroy(Request $request) |
|
100
|
|
|
{ |
|
101
|
|
|
TasksRequest::destroy($request->get('integer')); |
|
102
|
|
|
session()->flash('message', trans('FlashSession.tasksDestroy')); |
|
103
|
|
|
|
|
104
|
|
|
return redirect()->back(); |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
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.