How to sort collections by specific name and id. I need to sort records where the name = X should be the first in the order and the rest should be sort by id.
product model
|---------------------|------------------|
| id | Name |
|---------------------|------------------|
| 1 | a |
|---------------------|------------------|
| 2 | x |
|---------------------|------------------|
| 3 | b |
|---------------------|------------------|
| 4 | c |
|---------------------|------------------|
| 5 | x |
|---------------------|------------------|
| 6 | z |
|---------------------|------------------|
I tried this code but not working.
Product::orderBy('id', 'asc')->get()
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire