lundi 30 novembre 2020

Laravel how to sort collection by specific value and id

How to sort collections by specific value and id. I need to sort records where the name = X should be the first in the order.

product model

|---------------------|------------------|
|          id         |        Name      |
|---------------------|------------------|
|          1          |         a        |
|---------------------|------------------|
|          2          |         x        |
|---------------------|------------------|
|          3          |         b        |
|---------------------|------------------|
|          4          |         c        |
|---------------------|------------------|
|          5          |         x        |
|---------------------|------------------|

I tried this code but not working.

Product::orderBy('id', 'asc')->get()


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire