From the course: Advanced Laravel
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Write complex queries and create query scopes - Laravel Tutorial
From the course: 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…