Velvet Star Monitor

Standout celebrity highlights with iconic style.

news

ORDER BY "the date" Laravel 5 SQL Query

Writer Sophia Terry

I want to sort the results by the date, but this Laravel 5 SQL Query is not working as i want.

$b = DB::table('entry') ->select(DB::raw("DATE_FORMAT(created_at,'%d-%m-%Y') as tanggal")) ->groupBy(DB::raw("DATE_FORMAT(created_at,'%d-%m-%Y')")) ->orderBy(DB::raw("DATE_FORMAT(created_at,'%d-%m-%Y')"), 'asc') ->get();
2

1 Answer

Here's the easy way to achieve this

Step 1 :

Create a Model named as Entry by artisan command or manually

Step 2 :

Then from your Controller just do

$entry = Entry::orderBy('created_at', 'ASC')->get();

Then you should get the $entry array of what you need.

Hope this helps you

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy