I have a Laravel/PHP application with the following code:
try {
//gets the day of the last record for logged in user
$lastRecord = $user->records()->orderBy('date', 'DESC')->first()->date;
//convert to date
$lastTime = \Carbon\Carbon::createFromFormat('Y-m-d', $lastRecord);
}
catch(Exception $e) {
$lastTime = \Carbon\Carbon::now($user->timezone)->addDays(-1);
}
but I still get the error:
ErrorException in Habit.php line 104:
Trying to get property of non-object
Now I'm confused.. The main idea was to fail sometimes, and then continue to the catch block. How come it's still raising an error?