-
Notifications
You must be signed in to change notification settings - Fork 2
/
UpdateMemberRole.php
88 lines (76 loc) · 1.81 KB
/
UpdateMemberRole.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
<?php
namespace App\Livewire\Company;
use App\Models\User;
use Illuminate\View\View;
use Livewire\Component;
class UpdateMemberRole extends Component
{
public bool $isOpen = false;
/**
* Indicates if a user's role is currently being managed.
*
* @var bool
*/
public $currentlyManagingRole = false;
/**
* The user that is having their role managed.
*
* @var mixed
*/
public $managingRoleFor;
/**
* The current role for the user that is having their role managed.
*
* @var string
*/
public $currentRole;
/**
* Called when initializing the component
* @param User $user
* @return void
*/
public function mount(User $user)
{
$this->managingRoleFor = $user;
$this->currentRole = $this->managingRoleFor->getRoleNames()->first(function ($name) {
return $name != 'participant';
});
$this->currentlyManagingRole = true;
}
/**
* Returns all roles and descriptions available
* @return array
*/
public function getRolesProperty() : array
{
return config('roles');
}
/**
* Saves the new role of the member
* @return void
*/
public function save()
{
$this->managingRoleFor->syncRoles(['participant', $this->currentRole]);
$this->managingRoleFor = $this->managingRoleFor->fresh();
$this->currentlyManagingRole = false;
$this->isOpen = false;
}
/**
* Closes the modal
* @return void
*/
public function close()
{
$this->isOpen = false;
$this->currentRole = '';
}
/**
* Renders the component
* @return View
*/
public function render() : View
{
return view('livewire.company.update-member-role');
}
}