【发布时间】:2021-03-22 10:09:40
【问题描述】:
在 Laravel-5.8 中,我有这个代码:
$yearStatus = HrLeaveRequest::select('created_at')->where('employee_id', $userEmployee)->whereIn('leave_status', array(1, 3, 4))->orderBy('created_at', 'DESC')->first()->created_at;
//Get Specific current year from date
$specificYear = Carbon::createFromFormat('Y-m-d H:i:s', $yearStatus)->format('Y');
//Get Current Year
$currentYear = Carbon::now()->format('Y');
$currentDate = Carbon::now()->format('Y-m-d');
if ($currentYear > $specificYear){
$currentstatus = HrLeaveRequest::select('leave_status')->where('employee_id', $userEmployee)->whereIn('leave_status', [1, 3, 4])->orderBy('created_at', 'DESC')->first();
}else{
$currentstatus = HrLeaveRequest::select('leave_status')->where('employee_id', $userEmployee)->whereDate('resumption_date', '<=', $currentDate)->whereIn('leave_status', [1, 3, 4])->orderBy('created_at', 'DESC')->first();
}
无论何时:
$yearStatus = HrLeaveRequest::select('created_at')->where('employee_id', $userEmployee)->whereIn('leave_status', array(1, 3, 4))->orderBy('created_at', 'DESC')->first()->created_at;
为空,我收到此错误:
production.ERROR: ErrorException: Trying to get property 'created_at' of non-object
它指向:
$yearStatus = HrLeaveRequest::select('created_at')->where('employee_id', $userEmployee)->whereIn('leave_status', array(1, 3, 4))->orderBy('created_at', 'DESC')->first()->created_at;
我该如何解决这个问题?
谢谢
【问题讨论】:
标签: laravel