What seems to be the problem:
Hi, I am using Spatie and livewire in laravel 8.
to recover the role permissions to a checkbox works fine, but when I want to edit by marking it off and proceed to another, it is automatically marked
Steps to Reproduce:
in Role-component
public function edit($id)
{
$this->default();
$editar = Role::find($id);
$this->rol_id = $editar->id;
$this->name = $editar->name;
$this->permissions = Permission::get();
$this->rolePermissions = DB::table("role_has_permissions")->where("role_has_permissions.role_id", $this->rol_id)
->pluck('role_has_permissions.permission_id', 'role_has_permissions.permission_id')
->all();
foreach ($this->permissions as $permission) {
if (in_array($permission->id, $this->rolePermissions))
array_push($this->permission, $permission->id);
}
$this->view = 'edit';
}
in blade:
@foreach($permisos as $value)
<label class="inline-flex items-center">
<input type="checkbox" value="{{ $value->id }}" wire:model="permission" class="form-checkbox h-4 w-4 text-green-500">
<span class="ml-3 text-sm">{{ $value->name }}</span>
</label>
<br />
@endforeach
Do you have any screenshots or code examples: