У пользователя может быть много устройств, и у каждого устройства может быть много интерфейсов.
Я хочу получить пользователя с его устройствами и интерфейсами каждого устройства.
Модель пользователя
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
'profile_image', 'retrieve_email', 'retrieve_sms'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function devices()
{
return $this->hasMany('App\Device');
}
}
Модель устройства
class Device extends Model
{
public function interfaces()
{
return $this->hasMany('App\ModelInterface');
}
public function user()
{
return $this->belongsTo('App\User');
}
}
ModelInterface Model
class ModelInterface extends Model
{
public function device()
{
return $this->belongsTo('App\Device');
}
public function alerts(){
return $this->hasMany('App\Alerts');
}
}
Как получить интерфейсы пользователя?
Auth::user()->devices returns all the devices and works.
Как я мог сказать
Auther::user()->devices->interfaces