laravel-admin
laravel-admin copied to clipboard
Multi-select replaced by select for roles[column roles not working] in UserController. But it's show error
- Laravel Version: 10.2.0
- PHP Version:8.0.2
- Laravel-admin: 1.8
Description:
I am trying to remove multiselect and add only select in Usercontroller. But it's not working.The error is
Array to string conversion (View: project/encore/laravel-admin/resources/views/form.blade.php)
Steps To Reproduce:
public function form()
{
$userModel = config('admin.database.users_model');
$roleModel = config('admin.database.roles_model');
$form = new Form(new $userModel);
$form->select('roles', trans('admin.roles'))->options($roleModel::all()->pluck('name', 'id'));
return $form;
}
What's i am doing wrong. Any one can help me to find the solution.
add ->config('maximumSelectionLength', 1);
$form->multipleSelect('roles', trans('admin.roles'))->options($roleModel::all()->pluck('name', 'id'))->config('maximumSelectionLength', 1);
@Yanghsuanming thank you!
I also fix cascade linking issue adding a belongsToMany relation i.e.
`public function adminRole() { return $this->belongsToMany(AdminRole::class, 'admin_role_users', 'user_id', 'role_id');
}`
Above and your suggested method i.e. ->config('maximumSelectionLength', 1); works well in CREATE/Adding but unfortunately when EDIT it produce error:
ViewException In CanCascadeFields.php line 163 : addslashes(): Argument #1 ($string) must be of type string, array given (View: /vendor/encore/laravel-admin/resources/views/form.blade.php)
on line 163, that function is defined
/** * Js Value. */ protected function getValueByJs() { return addslashes(old($this->column(), $this->value())); }
i debug and found that $this->value() return array
array:1 [▼ // vendor/encore/laravel-admin/src/Form/Field/CanCascadeFields.php:163 0 => 5 ]
If i modify and return
$value=$this->value(); return addslashes(old($this->column(), $this->$value[0]));//i.e. 5
it works, but i donot want to change core file.
Any help please!