-
Notifications
You must be signed in to change notification settings - Fork 2
/
PresentationController.php
83 lines (68 loc) · 1.98 KB
/
PresentationController.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
<?php
namespace App\Http\Controllers;
use App\Models\Presentation;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
class PresentationController extends Controller
{
/**
* Returns the page to request a presentation
*
* @return View
*/
public function create(): View
{
if (Auth::user()->cannot('request', Presentation::class)) {
abort(403);
}
return view('presentations.create');
}
/**
* Processes the request for presentation
*
* @param Request $request
* @return mixed
*/
public function store(Request $request)
{
$user = Auth::user();
if ($user->cannot('request', Presentation::class)) {
abort(403);
}
$presentation =
Presentation::create($request->validate(Presentation::rules()));
if ($user->company) {
$presentation->update(['company_id' => $user->company->id]);
}
$user->joinPresentation($presentation, 'speaker');
$user->refresh();
return redirect(route('presentations.show', $presentation))
->banner("We successfully received your request to host a {$presentation->type}");
}
/**
* Return the basic show page for the presentation
*
* @param Presentation $presentation
* @return View
*/
public function show(Presentation $presentation): View
{
if (Auth::user()->cannot('view', $presentation)) {
abort(403);
}
return view('presentations.show', compact('presentation'));
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Presentation $presentation)
{
if (Auth::user()->cannot('delete', $presentation)) {
abort(403);
}
$presentation->delete();
return redirect(route('dashboard'))
->banner('You deleted your presentation request successfully');
}
}