DEV Community

Bellatreche Brahim
Bellatreche Brahim

Posted on

Answer: Sorting data in default rest api - Yii2 framework

There is no need to write code for it. Yii already supports inverse sorting by adding a negative sign to attribute name as shown here [Yii core code].

Unless name is not included in your model's safe attributes list, you can just use sort=-name instead of sort=name desc :

Top comments (0)