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.
0 comments:
Post a Comment
Thanks