Laravel Docs
##Использование Global Scopes
<?php
class ActiveScope implements ScopeInterface
{
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
public function apply(Builder $builder)
{
$builder->whereActive(1);
}
/**
* Remove the scope from the given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return void
*/
public function remove(Builder $builder)
{
$query = $builder->getQuery();
unset($query->wheres['active']);
}
}
trait ActiveTrait
{
public static function bootActiveTrait()
{
static::addGlobalScope(new ActiveScope);
}
}
class Post extends Eloquent
{
use ActiveTrait;
}