Answer the question
In order to leave comments, you need to log in
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:
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
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 questionAsk a Question
731 491 924 answers to any question