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
评论列表(0条)