Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

devionti's avatar

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.

0 likes
0 replies

Please or to participate in this conversation.