Hey,
I think I would do this in your controller:
$events = DB::table('<table name>')->orderBy('<field name>', '<direction>')->get();
So if your table is called events the code for getting them in descending order of creation date might be:
$events = DB::table('events')->orderBy('created_at', 'desc')->get();
You can find a bit more on this in the Laravel Docs - Ctrl + F and look for "Order By, Group By, And Having"
:)
This should be enough if you are using Eloquent:
$events = Event::orderBy('created_at', 'desc')->get();
baasjef said:
This should be enough if you are using Eloquent:
$events = Event::orderBy('created_at', 'desc')->get();
Thanks, It also worked!
And what if I want to order by time?
It seems, that, I need to store time in separate colum, right?
Ore, there is some way, to access, datetime field in mySQL and strip out time from string?
It is stored in DB like so --> 2014-05-31 10:00:00
P.S. I am ussing this extention --> http://jenssegers.be/projects/laravel-date
It is ordered by time already if you use created_at
eriktisme said:
It is ordered by time already if you use created_at
Yes,
I wanted to order, just by time, no mater what date, just time.
and that field name is ''datetimefrom'' from what date and time event starts.
But it seems, that to do that, I will need to store time in different columm. Right?
LOGINGRUPA said:
eriktisme said:
It is ordered by time already if you use created_at
Yes,
I wanted to order, just by time, no mater what date, just time.
and that field name is ''datetimefrom'' from what date and time event starts.
But it seems, that to do that, I will need to store time in different columm. Right?
Yes you need to do the time in a different column.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community