Before me is the task to output data from the database to the template, while the posts for which the boolean value is 0 should go at the top, and those at which 1, below. Is it possible to sort data from the database in laravel, by boolean field?

  • Yes, perhaps, like in any other field - xAoc

1 answer 1

What prevents them from sorting out as numbers? The boolean value in the database is tinyint, and is therefore easily sorted.

But if the exact order of the values ​​is important, you can use

$model->orderByRaw(); 

And there already write the standard string MYSQL

 ORDER BY FIELD()