lundi 21 septembre 2015

How to query relation in laravel scope

I have the following scope that I would like to amend slightly:

function scopeNotRunOut($query)
{
    return $query->has('redemptions', '<', DB::raw('quantity'));
}

This return all models where the related redemptions count is less than the quantity column. The redemptions table has a column for user_id so how would I tweak this so that it only counts redemptions where the user_id column is a given value?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire