nhayder
3 months ago

Call to a member function setCookie() on null

Posted 3 months ago by nhayder

Hey,

I have a middleware that forces blocked users when they are detected,

<?php

namespace App\Http\Middleware;

use Closure;
use Auth;

class RedirectBlockedAccounts
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {


            if(Auth::user()->status == 3)
            {

                Auth::logout();
                
                return view('errors.block');

            }

        
        return $next($request);

    }
}

the implementation above is returning error

Call to a member function setCookie() on null

is there is a fix for that?

Any Ideas

Please sign in or create an account to participate in this conversation.