Sql request to Eloquent ORM laravel


I have a small problem for a personal project and I confess I don’t really understand how to do it with eloquent from Laravel. I can make the sql query but I have a big problem converting it to eloquent.
Here is my problem: I would like to link two tables to an intermediate table.

Here is my intermediate table:
all columns :

dish_type_id |  recipe_id

Here is my recipe table:
all columns :

recipe_id|  label | image | etc...

Here is my dish_type table:
all columns :

dish_type_id |  dish_name

I would like display all the information of recipe and the dish with my intermediate table :
That’s my sql request :

select * from recipes_dish_type as rcpDish join dish_type dish on dish.DISH_ID = rcpDish.DISH_ID join recipes rcp on rcp.RECIPE_ID = rcpDish.RECIPE_ID;

For the moment, I have a Recipe and DishType model.

Is their any solution with eloquent to have the same thing?
I check belongsTo but there is only one way

Source: Laravel

Categorised as eloquent, laravel, php Tagged , ,


Leave a Reply

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us