first commit
This commit is contained in:
28
Livewire/Permissions/PermissionIndex.php
Normal file
28
Livewire/Permissions/PermissionIndex.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Koneko\VuexyAdmin\Livewire\Permissions;
|
||||
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class PermissionIndex extends Component
|
||||
{
|
||||
public $roles_html_select;
|
||||
public $rows_roles;
|
||||
|
||||
public function render()
|
||||
{
|
||||
// Generamos Select y estilos HTML de roles
|
||||
$this->roles_html_select = "<select id=\"UserRole\" class=\"form-select text-capitalize\"><option value=\"\"> Selecciona un rol </option>";
|
||||
|
||||
foreach (Role::all() as $role) {
|
||||
$this->rows_roles[$role->name] = "<span class=\"badge bg-label-{$role->style} m-1\">{$role->name}</span>";
|
||||
$this->roles_html_select .= "<option value=\"{$role->name}\" class=\"text-capitalize\">{$role->name}</option>";
|
||||
}
|
||||
|
||||
$this->roles_html_select .= "</select>";
|
||||
|
||||
return view('vuexy-admin::livewire.permissions.index');
|
||||
}
|
||||
}
|
35
Livewire/Permissions/Permissions.php
Normal file
35
Livewire/Permissions/Permissions.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Koneko\VuexyAdmin\Livewire\Permissions;
|
||||
|
||||
use Livewire\Component;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
|
||||
class Permissions extends Component
|
||||
{
|
||||
public $permissionName;
|
||||
|
||||
public function createPermission()
|
||||
{
|
||||
$this->validate([
|
||||
'permissionName' => 'required|unique:permissions,name'
|
||||
]);
|
||||
|
||||
Permission::create(['name' => $this->permissionName]);
|
||||
session()->flash('message', 'Permiso creado con éxito.');
|
||||
$this->reset('permissionName');
|
||||
}
|
||||
|
||||
public function deletePermission($id)
|
||||
{
|
||||
Permission::find($id)->delete();
|
||||
session()->flash('message', 'Permiso eliminado.');
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.permissions', [
|
||||
'permissions' => Permission::all()
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user