php ORDER BY“日期”Laravel 5 SQL 查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33820002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORDER BY "the date" Laravel 5 SQL Query
提问by Muhammad Haryadi Futra
I want to sort the results by the date, but this Laravel 5 SQL Query is not working as i want.
我想按日期对结果进行排序,但是这个 Laravel 5 SQL 查询没有按我想要的那样工作。
$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();
回答by Sulthan Allaudeen
Here's the easy way to achieve this
这是实现这一目标的简单方法
Step 1 :
第1步 :
Create a Model named as Entry
by artisan command or manually
Entry
通过 artisan 命令或手动创建一个名为 as 的模型
Step 2 :
第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.
然后你应该得到$entry
你需要的数组。
Hope this helps you
希望这对你有帮助