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
Trying to get property of non-object' pointing towards 'return $next($request);',
please can someone help me out, thanks in advance, Here is the page's code
<?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('/')->with('flash_error', 'Could not access, No Session Found.');
        }
        if (is_null($request->user())) {
            return redirect('/')->with('flash_error', 'You have been automatically logged out due to an extended period of inactivity.');
        }
        if (! $request->user()->isStaff()) {
            return redirect('/')->with('flash_error', 'Could not access, Permission Denied');
        }
        return $next($request);
    }
}
 
    