【发布时间】:2021-06-19 23:02:10
【问题描述】:
在我的 laravel 应用中,我注意到每条路由都执行了两次,但不知道为什么
例如:
Route::get('called_twice', function () {
dump('---');
});
两次返回字符串'---'
编辑:
为了追溯问题的根源,我在文件中放了一个转储
src/Illuminate/Foundation/Http/Kernel.php
protected function sendRequestThroughRouter($request)
{
$this->app->instance('request', $request);
Facade::clearResolvedInstance('request');
$this->bootstrap();
dump('kernel');
return (new Pipeline($this->app))
->send($request)
->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware)
->then($this->dispatchToRouter());
}
以及文件构造函数中的另一个转储
src/Illuminate/Pipeline/Pipeline.php
public function __construct(Container $container = null)
{
dump('pipeline');
$this->container = $container;
}
我明白了:
Pipeline 类被多次调用
Laravel 6.8.0
【问题讨论】:
-
它是在哪里定义的?
-
在 routes/api.php 文件中定义
-
你是否在使用 WAMP
-
@AlecJoy 不,正在运行 php artisan serve
标签: laravel