-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBoothController.php
127 lines (104 loc) · 3.62 KB
/
BoothController.php
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
namespace App\Http\Controllers\Crew;
use App\Http\Controllers\Controller;
use App\Mail\BoothApprovedMailable;
use App\Mail\BoothDisapprovedMailable;
use App\Models\Booth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
class BoothController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (Auth::user()->cannot('viewAny', Booth::class)) {
abort(403);
}
$booths = Booth::orderBy('is_approved')->paginate(15);
return view('crew.booths.index', compact('booths'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
if (Auth::user()->cannot('create', Booth::class)) {
abort(403);
}
return view('crew.booths.create');
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
// CURRENTLY NOT IN USE
abort(404);
if ($request->user()->cannot('create', Booth::class)) {
abort(403);
}
$input = $request->validate([
'company_id' => ['required', 'numeric', 'exists:companies,id'],
'width' => ['required', 'numeric', 'min:1', 'max:10'],
'length' => ['required', 'numeric', 'min:1', 'max:10'],
'additional_information' => ['nullable', 'max:255']
]);
$booth = Booth::create(array_merge($input, ['is_approved' => 1]));
$template = 'You created a booth for the :company';
return redirect(route('moderator.booths.index'))
->banner(__($template, [
'company' => $booth->company->name]));
}
/**
* Display the specified resource.
*/
public function show(Booth $booth)
{
if (Auth::user()->cannot('view', $booth)) {
abort(403);
}
return view('crew.booths.show', compact('booth'));
}
/**
* Approve or reject the specified resource in storage.
*/
public function approve(Booth $booth, bool $isApproved)
{
if (Auth::user()->cannot('approveRequest', $booth)) {
abort(403);
}
$isApproved = filter_var($isApproved, FILTER_VALIDATE_BOOLEAN);
$booth->handleApproval($isApproved);
$template = $isApproved ? 'You approved the booth of :company!'
: 'You denied the request of :company to have a booth';
if ($isApproved) {
if ($booth->company->representative->receive_emails) {
Mail::to($booth->company->representative->email)->send(new BoothApprovedMailable($booth->company));
}
return redirect(route('moderator.booths.show', $booth))
->banner(__($template, ['company' => $booth->company->name]));
} else {
if ($booth->company->representative->receive_emails) {
Mail::to($booth->company->representative->email)->send(new BoothDisapprovedMailable($booth->company));
}
return redirect(route('moderator.booths.index'))
->banner(__($template, ['company' => $booth->company->name]));
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Booth $booth)
{
if (Auth::user()->cannot('delete', $booth)) {
abort(403);
}
$booth->delete();
$template = 'You removed the booth of :company!';
return redirect(route('moderator.booths.index'))
->banner(__($template, ['company' => $booth->company->name]));
}
}