我使用带有复选框数组的 livewire 更新堆栈请帮助。形式
<form wire:submit.prevent="Update" class="py-3 mb-6">
@foreach ($permissions as $key => $pms)
<input type="checkbox" model:wire="PermissionCheckbox.{{ $key }}" {{ in_array($pms->id , $PermissionCheckbox)? "checked":"" }} />
@endforeach
<button class="btn btn-primary" type="submit">Update</button>
</form>
php函数
public function Edit($id){
$role = Role::find($id);
$this->roleId = $role->id;
$this->roleName = $role->name;
$this->PermissionCheckbox = json_decode($role->permissions->pluck('id'));
}
public function Update(){
$this->validate([
'roleName' => 'sometimes|required|unique:roles,name,'.$this->roleId,
'PermissionCheckbox' => 'required'
]);
dd($this->PermissionCheckbox);
}
结果不使用 PermissionCheckbox 更新。提前谢谢你们。