lundi 4 novembre 2019

Laravel Select Row with Unique column

I have one database as follow:

id, shop, order_number, Price 1, google, 11, 20 2, apple, 12, 20 3, google, 13, 20 4, google, 11, 20, 5, google, 11 , 20

If I use the follow command in laraval:

Order::where('shop','=','google')->orderBy('id','desc')->get()->toArray();

It will perfectly show me results where shop is google.

however, i want to return only unique results by order_number and where shop is google. It should return following result:

1, google, 11, 20 3, google, 13, 20

I try to use the following method:

Order::distinct()->where('shop','=','google')->orderBy('id','desc')->get(['id,shop,order_number,price'])->toArray();

But it seems not working.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire