Make your queries readable

Submitted by xroot - 10 years ago

Hi guys , I wanna share with you this trick that you may don't know or did not used it before . what if you want to do something like this . Animals::dogs(); or Animals::cats(); how you can achieve this ... well it's simple with eloquent


public function scopeDogs($query)
{
return $query->where('animal', '=', 'dog');
}

public function scopeCats($query)
{
return $query->where('animal', '=', 'cat');
}