У меня есть User
, Account
и Item
модели.
Account
имеет много User
отношений, а User
имеет много Account
отношений. Они определены как многие для многих.
Account
имеет много Item
отношений, и мне интересно, как получить все Item
для всех Account
отношений для User
.
// User.php:
public function accounts()
{
return $this->belongsToMany( Account::class );
}
// Account.php
public function users()
{
return $this->belongsToMany( User::class );
}
// Item.php
public function account()
{
return $this->belongsTo( Account::class );
}
Любая идея о том, как сделать звонок, как auth()->user()->items
или auth()->user()->accounts()->items
?