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()
{
parent::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.
You can do it
Project::withoutGlobalScope(ArchiveScope::class)->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With