1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Xetaravel\Livewire\Admin\Permission; |
6
|
|
|
|
7
|
|
|
use Illuminate\Contracts\View\Factory; |
8
|
|
|
use Illuminate\Contracts\View\View; |
9
|
|
|
use Illuminate\Foundation\Application; |
10
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests; |
11
|
|
|
use Livewire\Attributes\On; |
12
|
|
|
use Livewire\Component; |
13
|
|
|
use Masmerise\Toaster\Toastable; |
14
|
|
|
use Spatie\Permission\Models\Permission; |
|
|
|
|
15
|
|
|
use Xetaravel\Livewire\Forms\PermissionForm; |
16
|
|
|
|
17
|
|
|
class UpdatePermission extends Component |
18
|
|
|
{ |
19
|
|
|
use AuthorizesRequests; |
20
|
|
|
use Toastable; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The form used to create/update a model. |
24
|
|
|
* |
25
|
|
|
* @var PermissionForm |
26
|
|
|
*/ |
27
|
|
|
public PermissionForm $form; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Used to show the update modal. |
31
|
|
|
* |
32
|
|
|
* @var bool |
33
|
|
|
*/ |
34
|
|
|
public bool $showModal = false; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* When a user click on 'Edit' open the modal and set the content. |
38
|
|
|
* |
39
|
|
|
* @param Permission $permission |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
|
|
#[On('update-permission')] |
44
|
|
|
public function updatePermission(Permission $permission): void |
45
|
|
|
{ |
46
|
|
|
$this->authorize('update', $permission); |
47
|
|
|
|
48
|
|
|
$this->form->reset(); |
49
|
|
|
$this->form->permission = $permission; |
50
|
|
|
$this->form->name = $permission->name; |
51
|
|
|
$this->form->description = $permission->description; |
|
|
|
|
52
|
|
|
|
53
|
|
|
$this->showModal = true; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Update the permission. |
58
|
|
|
* |
59
|
|
|
* @return void |
60
|
|
|
*/ |
61
|
|
|
public function update(): void |
62
|
|
|
{ |
63
|
|
|
$this->authorize('update', $this->form->permission); |
64
|
|
|
|
65
|
|
|
$this->validate(); |
66
|
|
|
|
67
|
|
|
$this->form->update(); |
68
|
|
|
|
69
|
|
|
redirect() |
70
|
|
|
->route('admin.permission.index') |
|
|
|
|
71
|
|
|
->success('Your permission has been updated successfully !'); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function render(): View|Application|Factory|\Illuminate\View\View |
75
|
|
|
{ |
76
|
|
|
return view('livewire.admin.permission.update-permission'); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: