0

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

KordDEM
  • 177
  • 10

1 Answers1

0

If you want to create inline entries I would suggest to use the InlineCreateOperation, it can work in a BelongsToMany field too: https://backpackforlaravel.com/docs/5.x/crud-operation-inline-create

Cheers

Pedro X
  • 849
  • 5
  • 13