A
A
Alexer052021-09-13 19:06:52
Laravel
Alexer05, 2021-09-13 19:06:52

How to select posts for a specified city using Many to Many?

There are three tables
- posts
- cities
- post_city

How do I select posts only for the specified city? I did not find a solution in the documentation.

I tried to do it through the join () method when selecting posts (Post:: where ()-> join (), but then the data selection configured in the model, for example, in hasMany () stops working.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2021-09-13
@Alexer05

The task is the most trivial. You need a many-to-many relationship , whereHas and no joins. In the dock, everything is written in such detail and with examples that it’s impossible to figure it out ... well, that means it’s just too early)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question