dimanche 13 novembre 2016

How filter on calculated field (append) in Eloquent Laravel?

I have calculated property 'price' in model Room.

protected $appends = ['price'];

public function getPriceAttribute()
{
    if ($this->action) return $this->action_price_per_meter*$this->area;
    return $this->price_per_meter*$this->area;
}

When i filter Rooms by this virtual field ...

$rooms = Room::where('price','<',100000)->get();

of course i got error - Column 'price' not found

How to solve this problem in Laravel way?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire