ORDER BY "the date" Laravel 5 SQL Query
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