Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

saadaan's avatar

Session throwing coding error on timeout instead of logging out/in

Hi,

If I refresh my application page after some time, it throws a programming error, when actually there is no programming problem.

(2/2) ErrorException
Trying to get property of non-object (View: /mnt/hd/www/portal/resources/views/viewstaffdetail.blade.php)

in 2327d988b16cbfaa488e385b4ea0a498ecf8de55.php (line 31)
at CompilerEngine->handleViewException(object(ErrorException), 1)
in PhpEngine.php (line 44)
at PhpEngine->evaluatePath('/mnt/hd/www/portal/storage/framework/views/2327d988b16cbfaa488e385b4ea0a498ecf8de55.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'data_entry' => null))
in CompilerEngine.php (line 59)

Please note: It works fine if I do the login again. But I have to go to login page manually (laravel does not send me there automatically).

Help!

Thanks, Saad

0 likes
10 replies
Cronix's avatar

It sounds like your session timed out (expired). I'm guessing on the page that has the errors, you are using something that reads from session?

Seeing the relevant view would help.

saadaan's avatar

It seems like a session timeout, but its weird. Firstly, it is happening too quickly (like in 2 minutes or lesser). Secondly, I have noticed that if I update the controller, then this happens for sure. Is this a normal behaviour (controller update), even though I am not touching anything related to the session code?

Snapey's avatar

You are reading something such as Auth::user()->name in the header of the site or on the home page without checking you are actually logged in?

You should check, or use the null coalesce operator to catch trying to access an attribute of a null object

1 like
Cronix's avatar

Lots of things use session without you probably realizing it. Auth, like @snapey said, as well as form validation errors get put in session, etc. and other things as well.

You can see the form errors in your message: 'errors' => object(ViewErrorBag)

Are you trying to display form errors possibly?

saadaan's avatar

@Snapey Yes I am parsing Auth::user()->name in header. But I login properly all the time. Still it throws me out.

Now I discover that it is actually the sequence of pages that I follow, which for some reason causes this error. Still wondering why.

saadaan's avatar

So I have a STAFF model, a page to CREATE NEW STAFF, a second page which lists ALL CREATED STAFF, and a page to see the details of INDIVIDUAL STAFF. If I keep moving between first 2 pages (create/view all), it is fine. But if I go to see the details of any created staff, the detail page opens fine, but all other pages go whack. I cannot move back to create new staff or list all staff pages without forcibly logging in again.

Cronix's avatar

check all code in that controller and view and see if you are logging the user out, or wiping the session, etc.

Snapey's avatar
Snapey
Best Answer
Level 122

use the route helper to generate all the links between pages, otherwise you can have problems with links being relative to the current request and not relative to the root

2 likes
saadaan's avatar

This is my controller method for viewing staff detail. Looks innocent to me:

    public function show($id)
    {
          $data_entry = DB::table('data_portal')->where([['user_id','=',auth()->user()->id],['id','=',$id]])->first();

        return view('/viewstaffdetail', compact('data_entry'));
    }

Am I using auth()->user()->id in some wrong way?

saadaan's avatar

I think I got the issue. @snapey is right. It's relative path issue.

Thanks!

Please or to participate in this conversation.