How is the execution sequence of laravel middleware disrupted after encountering auth:api?

the following code:

Route::middleware(["cross" , "options", "auth:api"])->group(function(){
    Route::match(["get" , "post" , "options"] , "test/oauth" , "Test@oauth");
});

normal I think the middle execution order: cross-> options-> auth:api , but this side is very stupid! The actual execution order: auth:api-> cross-> options ! I"ve been fooled. Why is auth middleware given priority?

how can I get him to execute in order according to my intention? ( cross-> options-> auth:api )

Mar.21,2021

Laravel provides middleware priority, which is the default middleware priority, and others should be ranked after them

protected $middlewarePriority = [
    \Illuminate\Session\Middleware\StartSession::class,
    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
    \App\Http\Middleware\Cross::class,
    \App\Http\Middleware\Options::class,
    \Illuminate\Auth\Middleware\Authenticate::class,
    \Illuminate\Session\Middleware\AuthenticateSession::class,
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
    \Illuminate\Auth\Middleware\Authorize::class,
];
Menu