Skip to content

Instantly share code, notes, and snippets.

@vanchelo
Created August 14, 2014 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanchelo/b45dfffb8418b1c7013c to your computer and use it in GitHub Desktop.
Save vanchelo/b45dfffb8418b1c7013c to your computer and use it in GitHub Desktop.
<?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']);
}
}
class Post extends Eloquent
{
public static function boot() {
parent::boot();
static::addGlobalScope(new ActiveScope);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment