1 week ago

Disable global scope on model show?

Posted 1 week ago by seongbae

I have a model called project which can be archived. Archived projects do not show on the index page and I do that by using global scope on the Project model:

class ArchiveScope implements Scope
    public function apply(Builder $builder, Model $model)
        $builder->where('archived', false);

then within the Project model, I have:

protected static function boot()
        static::addGlobalScope(new ArchiveScope);

However, I have a page where I'm showing all archived projects and users should be able to click on each project, view the content, and un-archive the project if needed. But due to the global scope, it will not display the project. When I go to an archived project at /projects/{project_id}, it gives me 404 not found error. How can I apply withoutGlobalScope to the show operation of Project?

Thank you.


Please sign in or create an account to participate in this conversation.