Answer the question
In order to leave comments, you need to log in
How to create a relation in Laravel 5 through another relation?
Essence of the question. There are models and connections.
class Garage extends ApiModel
{
public function car()
{
return $this->belongsTo('Api\Models\Cars\Type', 'carId', 'car_id')->where('lang','pkw_de');
}
}
class Type extends Model
{
public function model()
{
return $this->belongsTo('Api\Models\Cars\Models', 'model_id', 'model_id')->where('lang', \Config::get('parameters.project.project_alias', 'pkw_de'));
}
public function maker()
{
return $this->belongsTo('Api\Models\Cars\Manufacturer', 'maker_id', 'maker_id')->where('lang', \Config::get('parameters.project.project_alias', 'pkw_de'));
}
}
class Models extends Model
{
public function group()
{
return $this->belongsTo('Api\Models\Cars\Group', 'group_id', 'group_id')->where('lang', \Config::get('parameters.project.project_alias', 'pkw_de'));
}
}
$cars = GarageModel::with('car','car.model','car.maker', 'car.model.group')->where('customerId', $customerId)->orderBy('createdAt', 'desc')->get();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question