【发布时间】:2020-04-11 22:09:32
【问题描述】:
在我的 Laravel-5.8 应用程序中,我想在数据库的另一个表中提取两个日期之间的假期数。我基本上有 2 张桌子:
hr_leave_requests
-
hr_holidays
class HrHoliday extends Model { protected $table = 'hr_holidays'; protected $fillable = [ 'holiday_name', 'holiday_date', 'created_at', ]; } class HrLeaveRequest extends Model { protected $table = 'hr_leave_requests'; protected $fillable = [ 'id', 'commencement_date', 'resumption_date', ]; }
在我的控制器中,我有:
$commencementDate = Carbon::parse($request->commencement_date);
$resumptionDate = Carbon::parse($request->resumption_date);
$holidays = DB::table('hr_holidays')->select('holiday_date')->whereYear('created_at', '=', date('Y'))->get();
$commencementDate and $resumptionDate are from hr_leave_requests
我该如何完成这个查询:
$holidays = DB::table('hr_holidays')->select('holiday_date')->whereYear('created_at', '=', date('Y'))->get();
获取 $commencementDate 和 $resumptionDate 之间的假期数。
谢谢。
【问题讨论】: