First you need to create your relationship,
<?php class Advert extends Eloquent { public function car() { return $this->belongsTo('Car'); } } class Car extends Eloquent { public function model() { return $this->belongsTo('Model'); } } class Model extends Eloquent { public function brand() { return $this->belongsTo('Brand'); } public function cars() { return $this->hasMany('Car'); } } class Brand extends Eloquent { public function models() { return $this->hasMany('Model'); } }
Then you just need to access this path:
echo Advert::find(1)->car->model->brand->name;
But your table fields will be like this because Laravel guesses that they are:
id (for all tables) car_id model_id brand_id
Or you will need to indicate them in relation.
source share