-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReasonManagementController.php
More file actions
96 lines (85 loc) · 2.82 KB
/
ReasonManagementController.php
File metadata and controls
96 lines (85 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace App\Http\Controllers\Dashboard\GameServer;
use App\Http\Controllers\Controller;
use App\Http\Requests\Dashboard\GameServer\Reason\StoreReasonRequest;
use App\Http\Requests\Dashboard\GameServer\Reason\UpdateReasonRequest;
use App\Models\GameServer\GameServer;
use App\Models\GameServer\Reason;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
class ReasonManagementController extends Controller
{
/**
* Show the form for creating a new reason.
*
* @param GameServer $server
* @return View
*/
public function create(GameServer $server): View
{
return view('admin.servers.reasons.create', compact('server'));
}
/**
* Store a newly created reason in storage.
*
* @param StoreReasonRequest $request
* @param GameServer $server
* @return RedirectResponse
*/
public function store(StoreReasonRequest $request, GameServer $server): RedirectResponse
{
$reason = Reason::create($request->safe()->except('months', 'days', 'hours', 'minutes'));
return redirect()->route('admin.servers.show', $server->id)->with([
'status' => 'success',
'message' => "Причина наказания \"$reason->title\" успешно добавлена!"
]);
}
/**
* Show the form for editing the specified reason.
*
* @param GameServer $server
* @param Reason $reason
* @return View
*/
public function edit(GameServer $server, Reason $reason): View
{
return view('admin.servers.reasons.edit', compact('server', 'reason'));
}
/**
* Update the specified reason in storage.
*
* @param UpdateReasonRequest $request
* @param GameServer $server
* @param Reason $reason
* @return RedirectResponse
*/
public function update(UpdateReasonRequest $request, GameServer $server, Reason $reason): RedirectResponse
{
$reason->update($request->safe()->except('months', 'days', 'hours', 'minutes'));
return back()->with([
'status' => 'success',
'message' => "Информация о причине наказания \"$reason->title\" успешно обновлена!"
]);
}
/**
* Remove the specified reason from storage.
*
* @param GameServer $server
* @param Reason $reason
* @return RedirectResponse
*/
public function destroy(GameServer $server, Reason $reason): RedirectResponse
{
if (!$server) {
return back()->with([
'status' => 'danger',
'message' => 'Ошибка!'
]);
}
$reason->delete();
return back()->with([
'status' => 'success',
'message' => "Причина \"$reason->title\" удалена!"
]);
}
}