V
V
Viktor Grachev2015-02-27 11:08:20
Laravel
Viktor Grachev, 2015-02-27 11:08:20

How to sort records using Laravel 4 pivot table?

Good morning! Can you please tell me how can I select all posts from the database using the sorting of the pivot table?
There is a Posts and Users table as well as a linking table post_user. The pivot table looks like this:
0ba815be97c3483488e3ac149818c4ee.jpg
I need to select all posts from the database that have the "checked" status everywhere using the data from the pivot table. The figure shows one post with such parameters. Please tell me how you can build such a query or with what conditions you can roughly build a query. I'm new to Laravel and I don't know how to build such queries yet)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gladkovskiy, 2015-02-27
@SMGladkovskiy

Victor, use the whereHas() method. The builder object that you will use in the closing contains information on the pivot table and on the "far" table in the many-to-many relationship. Refer to the pivot columns of the table with its name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question