Hey All,
I have a Quote model with a table column boolean('approved') which I want to use to setup two global scopes for "approved" and "not approved" quotes:
ApprovedScope.php
class ApprovedScope implements Scope
{
public function apply(Builder $builder, Model $model)
{
return $builder->where('approved', true);
}
}
Quote model:
class Quote extends Model
protected static function boot()
{
parent::boot();
static::addGlobalScope(new ApprovedScope);
// static::addGlobalScope(new NotApprovedScope);
}
public function author()
{
return $this->belongsTo('App\Author');
}
public function category()
{
return $this->belongsTo('App\Category');
}
You of course can't boot the model into two global scopes. But is there a solution to use both global scopes and define which one to use at controller level? Or the only way here is using Local Scopes?
Appreciate any ideas.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community