In this video, explore the ways in which you can write scope in Laravel Eloquent to create a simple and reusable set of conditions and constraints for retrieving records from the database.
- [Instructor] Scopes are the ability for us … to write conditions in Eloquent … and provide us straightforward wrapper … for adding those conditionals when we retrieve records. … The soft delete logic that we just saw … in the last video is utilizing a scope. … There is a global scope or a scope applied to all … queries for the model that removes soft deleted records … and the other scope that we saw withTrash … that includes soft deleted records. … Let's look at our controller where we've done … a lot of work building up conditionals … and replace all of this with the scope. … That's the ShowRoomsController at app, Http, … Controllers, ShowRoomController.php. … We've seen this a few times here where we're controlling … if we have a certain value to limit the room types … by that passed in value. … Let's move this to the scope … so we can see how they work. … We'll open the room model at app, Room.php. … We'll add some spaces after our lines setting our … various properties and add a new function here. …
- Exploring Laravel
- Setting up simple authentication
- Controllers and routes
- Create and index view
- Show, edit, and destroy views
- Writing scopes in Laravel Eloquent
- Creating one-to-one relationships
Skill Level Beginner
MVC Frameworks for Building PHP Web Applicationswith Drew Falkman2h 57m Intermediate
Ajax with PHP: Add Dynamic Content to Websiteswith Kevin Skoglund3h 37m Intermediate
What you should know1m 52s
2. Starting Your Project
3. The Create and Index Views
4. The Show, Edit, and Destroy Views
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.