Passed
Pull Request — master (#53)
by yasin
05:03
created

Update   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
c 0
b 0
f 0
dl 0
loc 46
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A updated() 0 3 1
A update() 0 11 3
A render() 0 5 1
A mount() 0 9 1
1
<?php
2
3
namespace EasyPanel\Http\Livewire\Admins;
4
5
use EasyPanel\Support\Contract\UserProviderFacade;
6
use Iya30n\DynamicAcl\Models\Role;
7
use Livewire\Component;
8
9
class Update extends Component
10
{
11
    public $admin;
12
13
    public $roles = [];
14
15
    public $selectedRoles = [];
16
17
    protected $rules = [
18
        'roles' => 'required'
19
    ];
20
21
    public function mount($admin)
22
    {
23
        $this->roles = Role::all();
24
25
        $admin = UserProviderFacade::findUser($admin);
26
27
        $this->admin = $admin;
28
29
        $this->selectedRoles = $admin->roles()->pluck('id');
30
    }
31
32
    public function updated($input)
33
    {
34
        $this->validateOnly($input);
35
    }
36
37
    public function update()
38
    {
39
        if ($this->getRules())
40
            $this->validate();
41
42
        if ($this->selectedRoles[0] == "null")
43
            $this->selectedRoles = [];
44
45
        $this->admin->roles()->sync($this->selectedRoles);
46
47
        $this->dispatchBrowserEvent('show-message', ['type' => 'success', 'message' => __('UpdatedMessage', ['name' => __('Admins')])]);
48
    }
49
50
    public function render()
51
    {
52
        return view('admin::livewire.admins.update', [
53
            // pass roles here.
54
        ])->layout('admin::layouts.app', ['title' => __('UpdateTitle', ['name' => __('Admins')])]);
55
    }
56
}
57