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:
1php artisan make:scope ClientScope
And the generated PHP class:
1namespace App\Scopes; 2 3use Illuminate\Database\Eloquent\Builder; 4use Illuminate\Database\Eloquent\Model; 5use Illuminate\Database\Eloquent\Scope; 6 7class ClientScope implements Scope 8{ 9 /**10 * Apply the scope to a given Eloquent query builder.11 *12 * @param \Illuminate\Database\Eloquent\Builder $builder13 * @param \Illuminate\Database\Eloquent\Model $model14 * @return void15 */16 public function apply(Builder $builder, Model $model)17 {18 // $builder->where('age', '>', 200);19 }20}
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.
0 comments:
Post a Comment
Thanks