Hello @kartik,
Global Scope is available:
class Article extends Post
{
protected $table = 'posts';
protected static function boot()
{
parent::boot();
static::addGlobalScope('article', function (Builder $builder) {
$builder->where('type', 'article');
});
static::creating(function ($article) {
$article->type = 'article'
});
}
}
where type = 'article' is added to all query of Article just like SoftDeletes.
>>> App\Article::where('id', 1)->toSql()
=> "select * from `posts` where `id` = ? and `type` = ?"
Actually laravel provide SoftDeletes trait using this feature.
Hope it helps!!