How to sort records using pivotal table Laravel 4?

Good morning! Please tell me how can I select from the database all the posts using the sort pivotal table?
There is a table Posts and Users as well as the junction table post_user. Pivota table is as follows:
I need to select all posts from the database which have a status of "cheked-out" using data from pivotal table. The figure marked a post with these parameters. Please tell me how can I build such a query, or by what conditions it is possible to build a query. TC I'm new to Laravel and I don't know yet how to build such queries)
September 19th 19 at 13:02
1 answer
September 19th 19 at 13:04
Victor, please use whereHas(). The object Builder, which you will use in —Ālosure, contains information on the pivot table and the "far" table in a many-to-many. Refer to columns of the pivot table specifying its name.
Thanks for the tip I tried to write:
$posts = Post::whereHas('users', function ($q) {
 $q->where('cheked-out', '=', 'cheked-out');

In the end, I got 3 post in the archive. Although if you look at the picture fully tested only 2 posts.
If you would like me to specify conditions that must be cheked-out against all the post_id to the post was approved by all users and only then it have to show in the archive - giuseppe.Beah commented on September 19th 19 at 13:07
See the SQL query that is eventually obtained. There may be restrictions on SoftDeleting functionality from posts or users that the machine impose restrictions.

Even just on the screenshot you can see that the result must be at least 5 values, and You write about 2 and 3... - lilliana_Hettinger30 commented on September 19th 19 at 13:10
Here are all the queries I have on the page:
I just don't quite understand how to make them correctly, well, judge for strictly. - giuseppe.Beah commented on September 19th 19 at 13:13
Well, first, for You to solve the problem, few will. It is purely Your responsibility. Here You will be given the opportunity to resolve the problem.
Second, even request in the first comments requests is different from what You posted the previous post. So let's take a more realistic example code (cleaned up, of course, from all the excess)
Third, You make the sample are in fact of the three tables and show data from a single intermediate.
Well, in the fourth, try to watch the original query, instead of ->get() write ->toSql(). Using this query, see what the data in the tables really are, you may run a query in the database to cut off the possibility of some changes on the way to Your browser...

In General - explore the issue, learn debit, the breakpoints to set and monitor the occurrence and impact of information. Without these skills You will be difficult to develop. Even if You will actively help to all sorts of resources, like the toaster. - lilliana_Hettinger30 commented on September 19th 19 at 13:16
Thank you Sergey for instructions and detailed answers. You are right that you need to comprehend all the intricacies of debugging in practice and learn what makes queries and gets the application. Will test further and see how to choose the right posts. I often just turn to the chat and community here with questions maybe the documentation for Laravel is very scarce and almost no practical examples with descriptions. So usually after a few days gugleniya seek help and counsel from more experienced colleagues)) thanks again and enjoy your weekend - giuseppe.Beah commented on September 19th 19 at 13:19
Mutually and success! - lilliana_Hettinger30 commented on September 19th 19 at 13:22

Find more questions by tags Laravel