Created
August 14, 2014 13:37
-
-
Save vanchelo/b45dfffb8418b1c7013c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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