Допустим, у вас есть модель
CarType для таблицы Типы автомобилей
CarBrand для таблицы car_brands и
CarModel для таблицы car_models
Вы можете использовать Eloquent: отношения для достижения этой цели
В вашей модели CarType
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CarType extends Model
{
/**
* Get the brands for the car .
*/
public function brands()
{
return $this->hasMany('App\CarBrand');
}
}
В вашей модели CarBrand вы можете выбрать тип автомобиля, к которому относится марка
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class CarBrand extends Model
{
/**
* Get the car that owns the brand.
*/
public function carType()
{
return $this->belongsTo('App\CarType');
}
}
например, вы можете сделать
$car = Car->find(1); // to get car with ID 1.
$brands = $car->brands; // brands of the selected car. You can loop through now
Также для бренда можно сделать
$brand = Brand->find(1) // For Brand ID 1
$car = $brand->carType;
Вы можете проверить Красноречивые отношения