在Laravel-5.8应用程序中,我只想在leave_status
为0
或所选雇员的行不存在时使创建按钮可见。
leave_status
,可以具有以下任意一个值0、1、2、3、4
控制器:
public function index()
{
try {
$userCompany = Auth::user()->company_id;
$userID = Auth::user()->id;
$userEmployee = Auth::user()->employee_id;
$render=[];
$leavetypes = HrLeaveType::where('company_id', $userCompany)->get();
$leaverequests = HrLeaveRequest::where('employee_id', $userEmployee)->where('company_id', $userCompany)->whereYear('created_at', date('Y'))->get();
$incompleteCount = $leaverequests->filter(function($item) {
return ($item->leave_status == 0);
})->count();
return view('service.leave_requests.index')->with(['leaverequests' => $leaverequests, 'incompleteCount' => $incompleteCount]);
} catch (Exception $exception) {
Session::flash('error', 'Action failed! Please try again');
return back();
}
}
查看:
@if ($incompleteCount)
<div style="margin-bottom: 10px;" class="row">
<div class="col-lg-12">
<a class="btn btn-info" href="{{ route("service.leave_requests.create") }}">
{{ trans('global.add') }} Leave Request
</a>
</div>
</div>
@endif
这仅在行中有数据时有效。但是当表为空时,它将隐藏按钮。
对于选定的员工,如何仅在表中没有数据且leave_status
为0
时使按钮可见?
谢谢