sofa/laravel-global-scope
Deprecated: Laravel 5.2+ changed global scopes, so this package is no longer valid. For Laravel 5.0–5.1, it provides an abstract Eloquent GlobalScope to define scopes via apply() and makes removing scopes from queries easier.
GlobalScope, but adds no meaningful value beyond basic apply() method enforcement. Modern Laravel’s built-in GlobalScope is functionally equivalent.addGlobalScope() and withoutGlobalScopes(). This package reduces to a single abstract class with no additional utility.remove() helpers).Sofa\GlobalScope classes to Laravel’s Illuminate\Database\Eloquent\Scope:
class PublishedScope implements Scope
{
public function apply(Builder $builder, Model $model)
{
$builder->where('published', true);
}
}
addGlobalScope() in the model’s boot() method:
protected static function boot()
{
static::addGlobalScope(new PublishedScope);
}
withoutGlobalScopes() for dynamic removal:
Model::withoutGlobalScopes(PublishedScope::class)->get();
sofa/laravel-global-scope from composer.json and update dependencies.apply().QueryException, dd($query->toSql())).Scope interface, but this is a one-time cost.query() method caching) work identically.where clauses, N+1 issues). Native scopes force explicit query building, reducing ambiguity.withoutGlobalScopes()) could cause performance issues. Native Laravel provides clearer error messages.remove()), migration may require significant refactoring.// Before (package)
class PublishedScope extends Sofa\GlobalScope {
public function apply(Builder $builder) { ... }
}
// After (native)
class PublishedScope implements Scope {
public function apply(Builder $builder, Model $model) { ... }
}
make:scope artisan command (if available) accelerate development.QueryBuilder assertions:
public function test_global_scope()
{
$query = Model::query();
$query->getQuery()->expects($this->once())->method('where')->with('published', true);
Model::all();
}
How can I help you explore Laravel packages today?