How can I use order by with findAll method in Yii2
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 ----
Model::find()->where([[‘attribute’=>‘value’]])->orderBy([‘attribute’=>SORT_DESC])->all();