Laravel Scopes Generator

Laravel Scopes Generator

The laravel-make-scope package by Samson Endale adds a make:scope command to the Artisan console. Here’s an example of creating a scope class with this command:

php artisan make:scope ClientScope

And the generated PHP class:

namespace App\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;

class ClientScope implements Scope
{
    /**
     * Apply the scope to a given Eloquent query builder.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $builder
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @return void
     */
    public function apply(Builder $builder, Model $model)
    {
        // $builder->where('age', '>', 200);
    }
}

You can read more about query scopes from the Laravel documentation. To learn more about this package, get full installation instructions, and view the source code on GitHub at SamAsEnd/laravel-make-scope.

Filed in: News / packages
Laravel News Partners

Laravel Jobs

Senior PHP developer
Brussels
Paynovate
PHP Developer - Full time w/ benefits, US Only
Northern Virginia or Remote (US Only)
Guidance Residential
Full Stack Developer
Remote
Wehaa.com
Laravel API Developer
Las Vegas, NV (Must work on-site)
V Shred
Laravel Developer (Vue, SQL Server)
Remote
World Trade Organization

Newsletter

Join 31,000+ others and never miss out on new tips, tutorials, and more.