lundi 22 juillet 2019

Laravel where - how to reference same modal with conditions?

I'd like to use some custom logic inside a 'where' condition (Laravel 5.8), e.g. the below. The 'where' parameter will change depending on a variable. The code below doesn't work, but gives you an idea of what I'm trying to achieve. How can I get the desired result?

\App\Model::where(function ($query) use ($quantity, $price_criteria) {
    if ($model->threshold_1 <= $quantity) {
        $compare = $model->price_1
    } elseif ($model->threshold_2 <= $quantity) {
        $compare = $model->price_2
    } else {
        $compare = $model->price_3
    } 
    $query->where($compare,"<=",$price_criteria)
}->orWhere...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire