You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

44 lines
1.0 KiB

<?php
namespace App\Components\Permission;
use Livewire\Component;
use Spatie\Permission\Models\Permission;
class Form extends Component
{
public $permissionId;
public $name;
protected function rules()
{
return [
'name' => 'required|string|unique:permissions,name' .
($this->permissionId ? ",{$this->permissionId}" : ''),
];
}
public function mount($permissionId = null)
{
$this->permissionId = $permissionId;
if ($permissionId) {
$perm = Permission::findOrFail($permissionId);
$this->name = $perm->name;
}
}
public function save()
{
$this->validate();
Permission::updateOrCreate(
['id' => $this->permissionId],
['name' => $this->name]
);
session()->flash('message', 'Permission saved.');
$this->emitUp('permissionSaved');
}
public function render()
{
return view('components.permission.form');
}
}