2016-04-30 63 views
0
$notif = DB::table('notifications')->orderBy('updated_at', 'desc')->get(); 

以上代码降upadated_at列是根据在laravel 5.缺省列的updated_at获得降序的值虽然将显示升序的值。我想先显示最近更新的那个。如何纠正?排序在laravel 5

Last column of this picture indicates the updated_at column. There I need to get the row which has the recent updated time first. How to solve that?

+0

你是如何检查结果是错误的顺序?我建议你使用梦幻般的“修补器”工具。 – whoan

+0

通过查看数据库表 –

回答

0

看起来你正在查看从phpMyAdmin的或类似的结果。代码

$ notif = DB :: table('notifications') - > orderBy('updated_at','desc') - > get();

会在您的Web应用程序中为您提供结果。 它不会像您预期的那样按降序将数据存储在数据库中。

0

您的陈述$notif = DB::table('notifications')->orderBy('updated_at', 'desc')->get();明确地给你正确的排序。正如@linuxartisan已经提到:你确定你用来显示数据库的工具使用正确的排序方向吗?看起来你的第一列中的11, 12id,排序顺序是使用id ascending