|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace App\Http\Controllers; |
|
5
|
|
|
|
|
6
|
|
|
use App\Http\Requests\StoreLocationRequest; |
|
7
|
|
|
use App\Models\Location; |
|
8
|
|
|
|
|
9
|
|
|
class LocationsController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Display a listing of the resource. |
|
14
|
|
|
* |
|
15
|
|
|
* @return \Illuminate\View\View |
|
16
|
|
|
*/ |
|
17
|
|
|
public function index() |
|
18
|
|
|
{ |
|
19
|
|
|
$locations = Location::with("compilations")->get()->sortBy("name"); |
|
20
|
|
|
$deletedLocations = Location::with("compilations")->onlyTrashed()->get(); |
|
21
|
|
|
return view( |
|
22
|
|
|
"locations.index", |
|
23
|
|
|
[ |
|
24
|
|
|
"locations" => $locations, |
|
25
|
|
|
"deleted_locations" => $deletedLocations |
|
26
|
|
|
] |
|
27
|
|
|
); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Store a newly created resource in storage. |
|
32
|
|
|
* |
|
33
|
|
|
* @param \App\Http\Requests\StoreLocationRequest $request |
|
34
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
35
|
|
|
*/ |
|
36
|
|
|
public function store(StoreLocationRequest $request) |
|
37
|
|
|
{ |
|
38
|
|
|
$location = new Location; |
|
39
|
|
|
|
|
40
|
|
|
$location->name = $request->input("name"); |
|
41
|
|
|
$location->save(); |
|
42
|
|
|
|
|
43
|
|
|
return \Redirect::route("locations.index"); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Show the form for editing the specified resource. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \App\Models\Location $location |
|
50
|
|
|
* @return \Illuminate\View\View |
|
51
|
|
|
*/ |
|
52
|
|
|
public function edit(Location $location) |
|
53
|
|
|
{ |
|
54
|
|
|
return view("locations.edit", ["location" => $location]); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Update the specified resource in storage. |
|
59
|
|
|
* |
|
60
|
|
|
* @param \App\Http\Requests\StoreLocationRequest $request |
|
61
|
|
|
* @param \App\Models\Location $location |
|
62
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
63
|
|
|
*/ |
|
64
|
|
|
public function update(StoreLocationRequest $request, Location $location) |
|
65
|
|
|
{ |
|
66
|
|
|
$location->name = $request->input("name"); |
|
67
|
|
|
$location->save(); |
|
68
|
|
|
|
|
69
|
|
|
return \Redirect::route("locations.index"); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Remove the specified resource from storage. |
|
74
|
|
|
* |
|
75
|
|
|
* @param \App\Models\Location $location |
|
76
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
77
|
|
|
*/ |
|
78
|
|
|
public function destroy(Location $location) |
|
79
|
|
|
{ |
|
80
|
|
|
$location->delete(); |
|
81
|
|
|
|
|
82
|
|
|
return \Redirect::route("locations.index"); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Restore the specified resource. |
|
87
|
|
|
* |
|
88
|
|
|
* @param int $locationId |
|
89
|
|
|
* @return \Illuminate\Http\RedirectResponse |
|
90
|
|
|
*/ |
|
91
|
|
|
public function restore(int $locationId) |
|
92
|
|
|
{ |
|
93
|
|
|
$location = Location::onlyTrashed()->where("id", $locationId)->get()->first(); |
|
94
|
|
|
$location->restore(); |
|
95
|
|
|
|
|
96
|
|
|
return \Redirect::route("locations.index"); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|