-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEventPolicyController.php
More file actions
56 lines (47 loc) · 1.32 KB
/
EventPolicyController.php
File metadata and controls
56 lines (47 loc) · 1.32 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
<?php
namespace App\Http\Controllers;
use App\Models\Event;
use App\Models\Policy;
use Illuminate\Http\Request;
use Throwable;
class EventPolicyController extends Controller {
/**
* Store a newly created resource in storage.
*/
public function store(Request $request, string $eventUUID) {
// Here we want to attach the provided Policy to the event...
$event = Event::where([
'uuid' => $eventUUID,
])
->firstOrFail();
$policy = Policy::where([
'id' => $request->policy_id,
'team_id' => $event->team_id,
])
->firstOrFail();
try {
$event->policies()
->attach($policy->id);
} catch (Throwable $e) {
// Do nothing
}
return back(303);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Request $request, string $eventUUID,
Policy $policy) {
$event = Event::where([
'uuid' => $eventUUID,
])
->firstOrFail();
try {
$event->policies()
->detach($policy->id);
} catch (Throwable $e) {
// Do nothing
}
return back(303);
}
}