-
Notifications
You must be signed in to change notification settings - Fork 2
/
RevokeRoleOfUser.php
50 lines (43 loc) · 1.02 KB
/
RevokeRoleOfUser.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
<?php
namespace App\Livewire\Crew;
use App\Models\User;
use Illuminate\Support\Facades\Gate;
use Illuminate\View\View;
use LivewireUI\Modal\ModalComponent;
use Spatie\Permission\Models\Role;
class RevokeRoleOfUser extends ModalComponent
{
public $user;
public $role;
/**
* Initializes a component
* @param $user
* @param $role
* @return void
*/
public function mount($user, $role)
{
if (!Gate::authorize('remove-crew-member')) {
abort(403);
}
$this->user = User::find($user);
$this->role = Role::find($role);
}
/**
* Triggered when the action is confirmed
* @return \Illuminate\Http\RedirectResponse
*/
public function confirm()
{
$this->user->removeRole($this->role);
return redirect()->to(route('moderator.crew.index'));
}
/**
* Renders the component
* @return View
*/
public function render() : View
{
return view('livewire.crew.revoke-role-of-user');
}
}