Set Middleware for Individual Route from Controller?

Posted 1 year ago by Splashsky

Hey guys! Working on a simple web game, and I'm trying to stick to resourceful controllers as much as I can for simplicity's sake. I need to apply a middleware to only one particular route of the controller...

public function create()
{
    $this->middleware('not-in-guild');
    return view('guilds.create');
}

This middleware only really determines if the authenticated user is in a guild or not. If they're in a guild, it's supposed to back() them...

public function handle($request, Closure $next)
{
    if (Auth::user()->inGuild()) {
        return back();
    }

    return $next($request);
}

but it doesn't do that. It just sends them right on to the view... how would I accomplish what I'm trying to do? o;

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