dimanche 1 septembre 2019

Laravel 5 hasMany relation returning incorrect relations

I have a Yard model and Treatment model, I am using the following hasMany relationship to return treatments that are currently active:

public function activeTreatments() {
    return $this->hasMany('App\Models\Treatment')
    ->where(function ($q) {
        $q->where('expires_at','>=', Carbon::now('Pacific/Auckland'))
        ->where('completed_at','>', Carbon::now('Pacific/Auckland'));
    })
    ->orWhere('completed',false);   
}

For some reason when I add the ->orWhere('completed',false) the query returns all treatments not just the treatments associated with the specific yard. What am I doing wrong here?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Py5wgh
via IFTTT

Aucun commentaire:

Enregistrer un commentaire