Skip to content

How to achieve withoutGlobalScopes() behaviour #123

@liepumartins

Description

@liepumartins

For some of our models we employ global scopes through the models boot() method. It is convenient, because those constrains do not need to repeated all over the application. Many relationship definitions etc.

e.g.

  protected static function boot(): void
    {
        parent::boot();
self::addGlobalScope('published', static function (Builder $query): void {
            $query->whereDate('from_date', '<=', Carbon::now())
                ->whereDate('to_date', '>=', Carbon::now());
        });
self::addGlobalScope('active', static function (Builder $query): void {
            $query->where('status', '=', 1);
        });
}

However JSON API faces a problem, "inactive" or "unpublished" records are not found - 404.

I do not see a way to pass withoutGlobalScopes() via schema.
What would be the suggested approach?
create a separate model without scopes for JSON API?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions