I have this code in Laravel-5.8 to filter the users within a set date as shown below:
public function userReport(Request $request)
{
$userCompany = Auth::user()->company_id;
$users= User::where('hr_status', 0)->where('company_id', $userCompany)->orderBy('last_login_at', 'desc');
$start_date = $request->start_date;
$end_date = $request->end_date;
$render=[];
if(isset($request->start_date) && isset($request->end_date))
{
$users=$users->whereBetween('last_login_at',[$start_date.' 00:00:00',$end_date.' 23:59:59']);
$render['start_date']=$request->start_date;
$render['end_date']=$request->end_date;
}elseif(isset($request->start_date))
{
$users=$users->where('last_login_at',$request->start_date);
$userr['start_date']=$request->start_date;
}
$users= $users->paginate(15);
$users= $users->appends($render);
$data['users'] = $users;
return view('report.userReport',$data);
}
The date for reference point is last_login_date
View
<div class="row" style="margin-bottom: 10px">
{{ Form::model(request(),['method'=>'get']) }}
<div class="col-sm-3">
{{ Form::date('start_date',null,['class'=>'form-control','placeholder'=>'Date']) }}
</div>
<div class="col-sm-3">
{{ Form::date('end_date',null,['class'=>'form-control','placeholder'=>'Date']) }}
</div>
<div class="col-xs-2">
{{ Form::submit('Search',['class'=>'btn btn-warning']) }}
</div>
{{ Form::close() }}
</div>
How do I complete the code in the controller to know the:
-
users that have logged- withing the specified date
-
users that have not logged-in within specified date
Thanks