Laravel middleware and router : Order of execution - Stack Overflow

i have question about the order execution between middleware and route. which one will be executed firs

i have question about the order execution between middleware and route. which one will be executed first. for example, i have dd('hello from middleware') and i also put dd('hello from router'), which one i will see on browser ?

example code :

Middleware :

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\View;

class EntryPointMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        dd('hello from the middleware');

        return $next($request);
    }
}

and code from routes\web.php

use Illuminate\Support\Facades\Route;
use App\Http\Middleware\EntryPointMiddleware;

Route::middleware([EntryPointMiddleware::class])->group(function() {
    dd('hello from the route');
});

the result that i got is "hello from the route", despite everyone saying that "hello from the middleware" is the one that i will see. so, why is the script inside the routes is executed first ?

and is it possible if i want the script inside middleware to be executed first instead of routes ? and how to do that ?

ps : i have use $middleware->priority([EntryPointMiddleware::class]) in bootstrap/app.php file (Laravel 11), but the result is same, i still got "hello from the route".

Thanks

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743905019a4527328.html

相关推荐

  • Laravel middleware and router : Order of execution - Stack Overflow

    i have question about the order execution between middleware and route. which one will be executed firs

    2天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信