Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 2 years ago.
0

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"

:)

Last updated 2 years ago.
0

This should be enough if you are using Eloquent:

$events = Event::orderBy('created_at', 'desc')->get();
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

It is ordered by time already if you use created_at

Last updated 2 years ago.
0

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?

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

LOGINGRUPA logingrupa Joined 24 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.