I have to dates. Now, I need to find the difference between these two for further calculations.
I tried different ways but I am not able to fix the issues. Can anyone tell me the best way to do it.
My code is:
public function leaveRequest(request $request)
{
$fdate=$request->Fdate;
$tdate=$request->Tdate;
$start = Carbon::parse($fdate)->format('Y/m/d');
$end = Carbon::parse($tdate)->format('Y/m/d');
$days = $end->diffInDays($start);
/*$days=date_diff($end,$start);*/
echo $days;
exit;
$user = User::findOrFail(Auth::user()->id);
Mail::send('pages.leave', ['user' => $request,'userId'=>$user], function ($m) use ($request) {
$m->to($request->Email)->subject('Leave Request!');
});
DB::table('leaves')->insert(
['user' => Auth::user()->id, 'request_date' => Carbon::now(),'start' => $start,'end' => $end,'permissions' => "Pending",'leave_status' => "Active"]
);
return redirect()->back()->with('message','Your request has sent');
}
If I can get the days then I can insert it into the leaves table.
$start = Carbon::parse($fdate);
and$end = Carbon::parse($tdate);
By using theCarbon::format()
function you got a string, so you would have received an error like "Call to member function diffInDays() on non-object" – Harpoon