$notif = DB::table('notifications')->orderBy('updated_at', 'desc')->get();
以上代碼降upadated_at列是根據在laravel 5.缺省列的updated_at獲得降序的值雖然將顯示升序的值。我想先顯示最近更新的那個。如何糾正?排序在laravel 5
$notif = DB::table('notifications')->orderBy('updated_at', 'desc')->get();
以上代碼降upadated_at列是根據在laravel 5.缺省列的updated_at獲得降序的值雖然將顯示升序的值。我想先顯示最近更新的那個。如何糾正?排序在laravel 5
看起來你正在查看從phpMyAdmin的或類似的結果。代碼
$ notif = DB :: table('notifications') - > orderBy('updated_at','desc') - > get();
會在您的Web應用程序中爲您提供結果。 它不會像您預期的那樣按降序將數據存儲在數據庫中。
您的陳述$notif = DB::table('notifications')->orderBy('updated_at', 'desc')->get();
明確地給你正確的排序。正如@linuxartisan已經提到:你確定你用來顯示數據庫的工具使用正確的排序方向嗎?看起來你的第一列中的11, 12
是id
,排序順序是使用id ascending
你是如何檢查結果是錯誤的順序?我建議你使用夢幻般的「修補器」工具。 – whoan
通過查看數據庫表 –