Whenever i leave my website for like 1 hour and whenever i try to access the different part of the website i get “Trying to get property ‘id of non object”, it means that the user have been logged out but the page crashed.
So i need a way so that i can apply a middleware to handle this issue??
can anyone help me??
Advertisement
Answer
Supposing that it is caused by user logged out due to session, you can apply a global middleware (applied to all route, or just the default auth middleware), to check if they are still logged in, and if they are not, you can redirect them back to login page. Something simply like this
if (Auth::user()){ return $next($request); } return redirect($yourLoginRoute);