Skip to content
This repository has been archived by the owner on Aug 3, 2021. It is now read-only.

olderThan() not working within scope() #45

Closed
skalero01 opened this issue Oct 7, 2020 · 1 comment
Closed

olderThan() not working within scope() #45

skalero01 opened this issue Oct 7, 2020 · 1 comment

Comments

@skalero01
Copy link
Contributor

skalero01 commented Oct 7, 2020

I have the next code on my model

public function cleanUp(CleanupConfig $config): void
    {
        $config->olderThan(now()->subMonth())
            ->scope(function($query) {
                $query->where('causer_type', 'like', '%SystemReport%')->orWhereNull('causer_type');
            });
    }

But when executing php artisan clean:models is removing all the rows that gets with the scope function without checking the created_at column.

It works if i change the code to this:

public function cleanUp(CleanupConfig $config): void
    {
        $config->scope(function($query) {
                $query->where('causer_type', 'like', '%SystemReport%')->orWhereNull('causer_type')->where('created_at', '<', now()->subMonth());
            });
    }

Is this normal behavior? I am using the last version available

@skalero01
Copy link
Contributor Author

Sorry, found the problem, i fixed it with this:

public function cleanUp(CleanupConfig $config): void
    {
        $config->olderThan(now()->subMonth())
            ->scope(function($query) {
                $query->where(function($query) {
                    $query->where('causer_type', 'like', '%SystemReport%')->orWhereNull('causer_type');
                });
            });
    }

Regards

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant