I have a table called proyectos
which has the following columns:
nombre
estado = [activo, inactivo, cerrado]
fecha_created
fecha_updated
c_users
(fk_user)
what I want to achieve is that I get the proyectos
according to the estado
and of form descendente
fecha_created
, so I did this:
$consulta = DB::table('proyecto')->where('c_users',Auth::user()->id)->orderBy('estado')->orderBy('fecha_created','desc')->get();
the query solves the problem for me orderBy('fecha_created','desc')
but the problem is with orderBy('estado')
what it generates, but just as I save it in the migrate
: activo
, inactivo
, cerrado
.
but I would like it to show me in the following way:
activos
cerrados
inactivos
How could I generate the way I want according to the state?
If we rely on the MySQL documentation, it indicates that the best ways to do an ordering on a column of type
ENUM
are:Example taken from the official documentation 1
For this case how are you in Laravel you should use the method
And compose the cast inside this method
Reference