mardi 23 janvier 2018

Middleware created in the construct method in controller throwing an error

I am trying to limit users to certain methods in my controller, I thus had to create a middleware in my construct method in my controller, it worked at first then when I wrote the second middleware all hell broke loose.

 public function __construct(){
    /*
        @Thirdwrist
        This is a a middleware that checks if a user has registered
        a profile, if the user is registered it redirects to the index
        of the profile controller, else it allows the user to access the 
        methods.
    */ 
    $this->middleware(function($request, $next){

        $id = Auth::id();
        if(Profile::where('user_id',$id)->count()){

            return redirect()->Route('profile.index');
        }
        else{
            return $next;
        }
    })->only(['create', 'store']);


    /*
        @Thirdwrist
        Middleware which checks if the user has a profile
    */ 
    $this->middleware(function ($request, $next){
        if (!Profile::where('user_id',Auth::id())->count()) {

            return redirect()->Route('profile.create');
        }
    })->except(['create', 'store']);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire