7 months ago

Can we go to different middleware based on current middleware?

Posted 7 months ago by kingshark


class Middleware1
     * Handle an incoming request.
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
    public function handle($request, Closure $next)
        if (...) {
            // next middleware is Middleware2
        } else {
            // next middleware is Middleware3

        // jump into next middleware


Sorry for not stating my full motivation here at first, now I state below:

This question is not for a real use case, but I'm digging into Laravel's middleware and Pipeline design, I want to know how far we can go in current pipeline pattern and want to copy the idea in other cases.

  • Does pipeline pattern itself requires all valves be setup before invoke?

  • If I want to implement a dynamic path way (same begin point, different path way and next road sometimes depend on previous result), what type of design I should consider?

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