title: Laravel - Trying to get property 'name' of non-object (View: C:\xampp\htdocs\jairusreport\resources\views\layouts\header.blade.php)
body: <p>I have an application on Laravel 5.8. Each time the user stays long on the application, this error come up</p>
  
  <blockquote>
    <p>Trying to get property 'name' of non-object (View: C:\xampp\htdocs\jairusreport\resources\views\layouts\header.blade.php) </p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/Oxw28.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Oxw28.png" alt="session error"></a></p>
  
  <p>For some days no I've been battling with a particular error and it has really wasted my time. I have done the screenshot of the error below.</p>
  
  <p>Auth/LoginController</p>
  
  <pre><code>class LoginController extends Controller   
  {
  use AuthenticatesUsers;
  protected $redirectTo = '/dashboard';
  
  protected function hasTooManyLoginAttempts ($request) {
      $maxLoginAttempts = 2;
      $lockoutTime = 5; // 5 minutes
      return $this-&gt;limiter()-&gt;tooManyAttempts(
          $this-&gt;throttleKey($request), $maxLoginAttempts, $lockoutTime
      );
  }  
  
  public function __construct()
  {
      $this-&gt;middleware('guest')-&gt;except('logout');
  }
  
  public function logout()
  {
      $user = Auth::user();
      Log::info('User Logged Out. ', [$user]);
      Auth::logout();
      Session::flush();
  
      return redirect(property_exists($this, 'redirectAfterLogout') ? $this-&gt;redirectAfterLogout : '/login');
  }    
  }
  </code></pre>
  
  <p>What is the cause of the problem. What do I do to resolve the issue.</p>