Level 7
What does your view controller look like?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I got this error "Trying to get property 'id' of non-object ..." when I reload my page. I know it is due to session expired and the object $user->id is no longer there. My question is how do I handle this?
I have this in my blade
var App = new Vue({
el: '#app',
data: {
urlCenter: '/manage/getuserrolecenterslist/{{ $user->id}}/4',
In my Handler.php
public function render($request, Exception $exception)
{
if ($exception instanceof HttpException) {
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
if ($request->ajax()){
return response('Unauthenticated', 401);
}
// redirect to login page
return redirect()->route('login');
}elseif ($exception instanceof TokenMismatchException) {
return redirect()->route('login');
}
return parent::render($request, $exception);
}
Please or to participate in this conversation.