samedi 18 août 2018

Laravel Eloquent Model scope multiple criteria

I have a question regarding the definition of a scope in my Laravel Eloquent Model

Situation: Model is 'Subscription', which has a.o. attributes 'startdate' and 'enddate'. Startdate is mandatory, Enddate is optionally filled or null

I defined a scope 'Active' as follows:

public function scopeActive($query)
    {
        return $query->whereDate('startdate', '<', Carbon::now())->whereDate('enddate', '>', Carbon::now());
    }

Bat as you can see this works fine when the enddate is filled (with a date in the future, but how can I add the condition that my startdate is earlier than today, and the enddate is null.

I assume there is a proper solution, but I could not find it in the documentation.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire