This is the way I do date filtering. In order to catch the start data and end date inject the Request
Object in to the index method.Then I would validate the data submitted and I convert the dates in to Carbon
Object which give more options like formatting the dates.lastly I use whereDate
eloquent query function to compare dates. So the end result would be something like this.
public function index(Request $request)
{
this->validate($request,[
'start_date' => 'required|date',
'end_date' => 'required|date|before_or_equal:start_date',
]);
$start = Carbon::parse($request->start_date);
$end = Carbon::parse($request->end_date);
$get_all_user = User::whereDate('date','<=',$end->format('m-d-y'))
->whereDate('date','>=',$start->format('m-d-y'));
return view('userPage.index', compact('get_all_user'));
}