mohammedmanssour / laravel-recurring-models

The ultimate solution for adding recurring functionality to your Laravel Models!
MIT License
249 stars 20 forks source link

[Bug]: whereOccurresBetween is wrong #9

Closed Sergiobop closed 9 months ago

Sergiobop commented 1 year ago

What happened?

whereOccurresBetween method is bugged atm, since it produces wrong queries. The orWhere should be grouped inside a where clause.

How to reproduce the bug

Just use the whereOccurresBetween scope.

The right method should be implemented like this:

public function scopeWhereOccurresBetween(Builder $query, CarbonInterface $start, CarbonInterface $end): Builder
    {
        $dates = CarbonPeriod::create(
            $start,
            $end,
        );

        $query->where(function (Builder $query) use ($dates) {
            foreach ($dates as $date) {
                $query->orWhere(fn ($query) => $query->whereOccurresOn($date));
            }
        });

        return $query;
    }

Package Version

0.5.1

PHP Version

8.1

Laravel Version

10.0

Which operating systems does with happen with?

No response

Notes

I had to override the scope in my model to make it work.