Yii2 - order by in findAll method

How can I use order by with findAll method in Yii2

Yeah, I found the solution. We can use the orderBy() with find() method like the following:


Model::find(['attribute'=>'value'])->orderBy(['attribute'=>SORT_DESC])->all(); // sort descending


-model-------parameter conditions---------------attribute to sort-------fetch all ----

:)

1 Like

Model::find()->where([[‘attribute’=>‘value’]])->orderBy([‘attribute’=>SORT_DESC])->all();