Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Easy Laravel Book:
Using Scopes With Laravel 5
Jun 24, 2015 @ 11:10:45

The "Easy Laravel Book" website has posted a new tutorial today looking at the use of scopes in Laravel, a packaging method for creating reusable chunks of code for use across the application.

Applying conditions to queries gives you to power to retrieve and present filtered data in every imaginable manner. Some of these conditions will be used more than others, and Laravel provides a solution for cleanly packaging these conditions into easily readable and reusable statements, known as a scope. In this tutorial I’ll show you how to easily integrate scopes into your Laravel models.

He starts with a simple example of a "where" clause made into a method having a name starting with "scope". This is a hard-coded scope but he also shows an example of the other option, dynamic scopes, allowing for input from the user as a part of the execution. He also shows a quick example of using these same scopes with relations, making them a part of the "find" result chain.

tagged: laravel5 easylaravelbook scopes tutorial

Link: http://www.easylaravelbook.com/blog/2015/06/23/using-scopes-with-laravel-5/