PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, November 16, 2022

[FIXED] How can i handle the page crash in laravel?

 November 16, 2022     laravel, laravel-6.2, php     No comments   

Issue

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??

enter image description here'


Solution

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);


Answered By - Edward Chew
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,214,417

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing