Aug 30, 2020
0
Level 2
BelongsToMany Filtering - Nova
I have three tables, well 5 if you count the pivot. tables:Helpdesk, users, subject pivot tables:users_subject, users_helpdesk All I want is that helpdesk has sub_id, now I want when I select the dropdown list for users in the belnogstomany it would only show up users that have the same sub_id. In Nova there is a belongsToMany field. The issue is I am unsure how to filter the users in the attach users.
BelongsToMany::make('Users','users', \App\Nova\User::class),
public function users()
{
return $this->belongsToMany('App\User', 'users_helpdesk', 'helpdesk_id', 'user_id')->withPivot('user_id', 'helpdesk_id')->withTimestamps();
}
public function getUsers()
{
return $query = DB::table('users_subject')
->join('users', 'users.id', '=', 'users_subject.user_id')
->select( 'users.name')
->get();
}
If I made users as a BelongsTo then its easier to make a dependent dropdown list.
Please or to participate in this conversation.