-2

How to add an orderBy() with a where condition?

$floor_data = Floors::find()->where(['building_id' => $id])->orderBy->(['floor_no' => SORT_DESC])->all();

This is giving me a syntax error saying

syntax error, unexpected '(', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'

jarlh
  • 42,561
  • 8
  • 45
  • 63
Sarath C
  • 13
  • 3

1 Answers1

0

The extra -> caused the error:

$floor_data = Floors::find()
    ->where(['building_id' => $id])
    //   Remove ↓↓   
    // ->orderBy->(['floor_no' => SORT_DESC])
    ->orderBy(['floor_no' => SORT_DESC])
    ->all();
Calos
  • 1,783
  • 19
  • 28