Retrieve data in pivot table many to many relationship

So I have two models Location and Company with many to many relationship, I want to get all the locations related to the company and the current_company_id of the auth user. Here is the relationship that I'm using. public function locations(): BelongsToMany { return $this->belongsToMany(Location::class) ->using(CompanyLocation::class) ->wherePivot('company_id', auth()->user()->current_company_id); } This is where I want to get all the locations: Forms\Components\Select::make('location') ->label('Location') ->multiple() ->relationship('locations','location_name') ->preload() ->createOptionForm([ Forms\Components\TextInput::make('location_name') ->required(), ]), Here is what I'm getting it seems like it is selecting the locations table and not the pivot table.
No description
1 Reply
John
John15mo ago
The relationship is in the Company model, right? Why would you ->wherePivot()? Isn't the company ID also in ->where('id')? And the locations data is expected to be in the locations table and not in the pivot table, isn't it?
Want results from more Discord servers?
Add your server