Level 8
Is the DishCategory already a relation of the Dish?
If so, you can use the with method like dishes.dish_category https://laravel.com/docs/9.x/eloquent-relationships#nested-eager-loading
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi I have a Menu controller that return a detail menu page that have dishes and every dish have a category. In this way I send the menu with dishes but how could I access to the dish category?
public function singleMenuPage(Request $request)
{
$menu = Menu::with('dishes')->where('name', unslug($request->route('menuName')))->get();
return Inertia::render('MenuPage', ['menu' => $menu]);
}
[
{
"id": 1,
"name": "Pasta e patate",
"dish_category_id": 2,
"price": "9.20",
"is_active": 1,
"created_at": "2022-12-21T13:26:11.000000Z",
"updated_at": "2022-12-21T13:26:11.000000Z",
"pivot": {
"menu_id": 1,
"dish_id": 1
}
},
{
"id": 2,
"name": "Arrosto di vitello",
"dish_category_id": 3,
"price": "15.50",
"is_active": 1,
"created_at": "2022-12-21T13:26:11.000000Z",
"updated_at": "2022-12-21T13:26:11.000000Z",
"pivot": {
"menu_id": 1,
"dish_id": 2
}
}
]
Please or to participate in this conversation.