protected static function booted()
{
self::addGlobalScope('latest', function ($query){
$query->latest('updated_at');
});
}
public function boot()
{
parent::boot();
Route::bind('project', function($id) {
return AppProject::withoutGlobalScopes()->findOrFail($id);
});
}
Model::withoutGlobalScopes()->get();
<?php
namespace AppModels;
use IlluminateDatabaseEloquentModel;
class User extends Model
{
/**
* Scope a query to only include popular users.
*
* @param IlluminateDatabaseEloquentBuilder $query
* @return IlluminateDatabaseEloquentBuilder
*/
public function scopePopular($query)
{
return $query->where('votes', '>', 100);
}
/**
* Scope a query to only include active users.
*
* @param IlluminateDatabaseEloquentBuilder $query
* @return void
*/
public function scopeActive($query)
{
$query->where('active', 1);
}
}
public function apply(Builder $builder, Model $model)
{
$builder->where('age', '>', 200);
}
protected static function boot()
{
parent::boot();
static::addGlobalScope(new ArchiveScope);
}