如何获取在laravel上过去24小时或过去30天内创建的数据

时间:2018-05-04 19:27:29

标签: database laravel laravel-5

如何获取过去24小时或过去30天内创建的数据

            $last['last_trades'] = Credit::where
    ('user_id', $user->id)->where('description',
         '#1 Bonus Trade')->where('currency_code', 'LTC')->limit(5)->orderby
('created_at', 'DESC')->get(); 

1 个答案:

答案 0 :(得分:0)

使用碳:

use Carbon\Carbon;

...

$last['last_trades'] = Credit::where('user_id', $user->id)
    ->where('description', '#1 Bonus Trade')
    ->where('currency_code', 'LTC')
    ->where('created_at', '>', Carbon::now()->subDays(30)->startOfDay())
    ->limit(5)
    ->orderBy('created_at', 'DESC')
    ->get()