Laravel select查询,自给定日期起30天
我正在尝试构建这个查询,其中我的日期比我创建的时间多30天 下面是我所拥有和需要的Laravel select查询,自给定日期起30天,laravel,Laravel,我正在尝试构建这个查询,其中我的日期比我创建的时间多30天 下面是我所拥有和需要的 ->select('orders.invoice_no as invoice_no', 'users.name as customer_name', 'orders.created_at as invoice_date', 'orders.created_at (need to plus 30 days here) as due_date) 基本上,当我的创建日期为到期日时,我需要在该特定部分添加30天,
->select('orders.invoice_no as invoice_no', 'users.name as customer_name', 'orders.created_at as invoice_date', 'orders.created_at (need to plus 30 days here) as due_date)
基本上,当我的创建日期
为到期日
时,我需要在该特定部分添加30天,以便我的到期日
比我的创建日期
多30天
我将感谢任何和所有的帮助。干杯 尝试将DB::raw与
间隔一起使用
->选择('orders.invoice\u no as invoice\u no','users.name as customer\u name','orders.created\u as invoice\u date',DB::raw('(orders.created\u at+INTERVAL 30天)as due\u date'))
或者将selectRaw与间隔一起使用
->选择原始('orders.invoice\u no as invoice\u no,users.name as customer\u name,orders.created\u as invoice\u date,(orders.created\u at+INTERVAL 30 DAY)as due\u date')
你可以这样做
$duedate = Orders::find(1);
$duedate->created_at->addDays(30);
检查此项,它必须与DB::raw一起使用,对吗?我可以使用DB::table吗?@UdhayanNair您只需添加DB::raw('(orders.created_,间隔30天)作为到期日)
在您的选择中,它可以与雄辩的生成器或查询生成器一起使用。
->select('orders.invoice_no as invoice_no', 'users.name as customer_name', 'orders.created_at as invoice_date', DATE_ADD('orders.created_at', INTERVAL 30 DAY) as due_date)