In my setupCreateOperation
I am successfully using select_from_array
to show a multi-select list
//Get a list of Roles as IDs
$roles = $this->getRoles();
CRUD::field([ // select_from_array
'name' => 'roles',
'label' => 'Roles',
'type' => 'select_from_array',
'options' => $roles->toArray(),
'allows_null' => false,
'allows_multiple' => true,
]);
But in the setupUpdateOperation
I want to show the current choices as already selected, but I can’t see how to do that from the docs. I was expecting something like
//Get a list of Roles as IDs
$roles = $this->getRoles();
//Add an array of roles
CRUD::field([ // select_from_array
'name' => 'roles',
'label' => 'Roles',
'type' => 'select_from_array',
'options' => $roles->toArray(),
'allows_null' => false,
'selected' => $this->crud->getCurrentEntry()->roles
'allows_multiple' => true,
]);
*I am only trying backpack in my project before I buy to I don’t have Pro and therefore don’t have relationship fields yet