Я индексирую яблоки с заданными свойствами (например, цветом) с помощью API Laravel.Я использую объединение, чтобы получить яблоки, которые относятся к указанному бренду.но он не извлекает яблоки с их собственными заданными свойствами, которые определены в другой БД и моделях.
public function index(Brand $brand)
{
$apples = Apple::join('brands', 'brand_id', 'brands.id')->where('brand_id', $brand->id)->get();
return returnSuccessfulResponse(
trans('api.response.successful.index'),
Resource::collection($apples)
);
}
Модель Apple:
public function brand()
{
return $this->belongsTo(Brand::class);
}
public function appleProperties()
{
return $this->hasMany(AppleProperty::class);
}
Ресурс:
return [
'id' => $this->brand->id,
'name' => $this->brand->name,
'apple-properties' => $this->appleProperties,
];
Маршрут:
Route::apiResource('brands/{brand}/apples', 'AppleController');
Не восстанавливается appleProperties
.Я не понимаю эту причину!