dimanche 7 juillet 2019

Where + orWhere with Limit but force including specific results

I need to query some rows with where, orderBy and limit, i'll order then by the price, but i need to force the orders that are from the user who is querying to be on the query, not necessary they will be because maybe the price is not on the top of the orderBy, i tried the code below but seems that i can't use orderBy inside a subquery, is this query even possible?

    Orders::where('status', 'active')
        ->where('user_id', 385)
        ->orWhere(function ($query) {
            $query->where('status', 'active')
                    ->orderBy('price', 'asc');
        })
        ->limit(10000)
        ->get();

the query results variable orders...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire