【问题标题】:how to convert query php to laravel framework如何将查询php转换为laravel框架
【发布时间】:2020-10-14 22:40:42
【问题描述】:

如何将此查询转换为 Laravel 查询

SELECT * FROM dbx_a 
WHERE date BETWEEN NOW() - INTERVAL 30 DAY AND NOW() AND name = 'MANAGEMENT' 
ORDER BY date DESC

【问题讨论】:

标签: laravel


【解决方案1】:

您可以使用carbon 来帮助您构建查询:

 $beforeThirtyDay = Carbon::now()->subDays(30);
 DB::table('dbx_a')->select('*')->whereBetween('date', array(Carbon::now(), $beforeThirtyDay))
            ->where('name', '=', 'MANAGEMENT')->orderByDesc('date')->get();

【讨论】:

    【解决方案2】:

    请试试这个:

    DB::table('dbx_a')
      ->whereRaw('date BETWEEN NOW() - INTERVAL 30 DAY AND NOW()')
      ->where('name', 'MANAGEMENT')
      ->orderByDesc('date')
      ->get();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-23
      • 2021-12-08
      • 1970-01-01
      相关资源
      最近更新 更多