use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; // Example Model: App\Models\Post class Post extends Model { // Define a global scope for 'published' posts protected static function booted() { static::addGlobalScope('published', function (Builder $builder) { $builder->where('is_published', true); }); } } // Usage: // Retrieves only published posts (global scope automatically applied) $publishedPosts = Post::all(); // Retrieves all posts, including unpublished ones (removing the global scope) $allPosts = Post::withoutGlobalScope('published')->get(); // Retrieve all posts, ignoring all global scopes $allPostsIgnoringAllScopes = Post::withoutGlobalScopes()->get();