I think it would be easier to do a separate query in this case.
Jul 3, 2016
2
Level 11
Pivot and next foreign key(s)
Hello, i have simple three tables (user, bookmaker and pivot table bookmaker_user).
In pivot table except standard columns (user_id, bookmaker_id) I also have several few columns, eg. a foreign key currency_id.
If I want get this value, I know, that in models I must have this:
// User model
public function bookmakers() {
return $this->belongsToMany(Bookmaker::class)->withPivot('currency_id');
}
The question is: Is there any way that instead of id (number) in currency_id attribute gain equal access to the entire data object from a currencies table, like currency name?
Something like:
$user->bookmakers()->first()->pivot->currency->name
?
Thank for all answers.
Please or to participate in this conversation.