title: 'Trying to get property of non-object'
body: <p>When i click the link on my site to go to a page , it gives me an error 500 message, when i check the error it comes back with </p>
  
  <blockquote>
    <p>Trying to get property of non-object' pointing towards 'return $next($request);',</p>
  </blockquote>
  
  <p>please can someone help me out, thanks in advance,
  Here is the page's code</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Middleware;
  
  use Closure;
  
  class StaffAuth
  {
      /**
       * Handle an incoming request by checking to see if the user is a member of Staff.
       *
       * @param \Illuminate\Http\Request $request
       * @param \Closure                 $next
       *
       * @return mixed
       */
  
  public function handle($request, Closure $next)
      {
          if (is_null($request)) {
              return redirect('/')-&gt;with('flash_error', 'Could not access, No Session Found.');
          }
  
          if (is_null($request-&gt;user())) {
              return redirect('/')-&gt;with('flash_error', 'You have been automatically logged out due to an extended period of inactivity.');
          }
  
          if (! $request-&gt;user()-&gt;isStaff()) {
              return redirect('/')-&gt;with('flash_error', 'Could not access, Permission Denied');
          }
  
          return $next($request);
      }
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/jwtzO.png" rel="nofollow noreferrer">Error</a></p>