I have two model Users and Roles connected by a pivot table. I want to display a field from the role model in CrudUserController. For example User model:
public function roles()
{
return $this->belongsToMany( Role::class, 'role_user', 'user_id', 'role_id');
}
Role model
public function user()
{
return $this->belongsToMany( User::class, 'role_user','role_id','user_id');
}
UserCrudController
$this->crud->addFields([
[
'type' => 'repeatable',
'label' => 'Role',
'name' => 'roles', <- this field shows select2 with a list of roles
'subfields' => [
[
'name' => 'description', <- this field is from the role model, it should change when changing the role in select2
'label' => 'Description',
'type' => 'text',
]
]
]
])
I'm not sure if this is possible because usually such manipulations are implemented using js