课程: Advanced Laravel

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

Write complex queries and create query scopes

Write complex queries and create query scopes - Laravel教程

课程: Advanced Laravel

Write complex queries and create query scopes

- [Shruti] Let's book this class once again. Class is booked, great, but if you come back to the list of classes you'll still see this class appearing. The member shouldn't be able to see this once it's booked, right? So we need to edit the query to remove booked classes from this list. In other words, for each scheduled class we want to check the list of booked members and remove that row if our user ID is found meaning we have to remove that scheduled class if the relationship exists. Eloquent allows us to query the relations using various methods like has, where has, where doesn't have, and so on. You can go to the documentation, search for querying relationship existence, right here. And then you can also look for querying relationship absence. In our case right now, we need to query relationship absence because we need those classes which are not booked by the authenticated user. That means where the…

内容