Make your queries readable

Submitted by xroot - 3 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');
}

Ads cover the costs of maintaining Laravel-tricks

comments powered by Disqus

Ads cover the costs of maintaining Laravel-tricks