Ini*_*igo 5 middleware laravel laravel-5 laravel-middleware
就像标题一样。Laravel 5.6中的默认API中间件列为Kernel.php:
protected $middlewareGroups = [
'api' => [
'throttle:60,1',
'bindings',
],
];
Run Code Online (Sandbox Code Playgroud)
我很感谢外行对功能的解释bindings,这在任何地方都找不到。
它使用SubstituteBindings具有handle方法的类:
public function handle($request, Closure $next)
{
$this->router->substituteBindings($route = $request->route());
$this->router->substituteImplicitBindings($route);
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
尽管我仍然不了解它的作用。
我认为你要求的是这个https://laravel.com/docs/5.7/routing#route-model-binding
Route::get('api/users/{user}', function (App\User $user) {
return $user->email;
});
Run Code Online (Sandbox Code Playgroud)
它立即绑定 User 模型。
我有同样的问题,并且能够找到:
“
Route model binding现在正在使用的中间件来实现所有的应用程序应该在你的应用程序/ HTTP / Kernel.php文件中添加照亮\路由\中间件\ SubstituteBindings到您的Web中间件组:\ Illuminate \ Routing \ Middleware \ SubstituteBindings :: class,
您还应该在HTTP内核的$ routeMiddleware属性中注册用于绑定替换的路由中间件:
'bindings'=> \ Illuminate \ Routing \ Middleware \ SubstituteBindings :: class,...”
可以在此页面上找到-https://laravel.com/docs/5.3/upgrade
上面的答案最初来自此来源-/sf/answers/3344894381/
因此,在我看来,bindings中间件只是捷径\Illuminate\Routing\Middleware\SubstituteBindings::class-如果正确,我不确定Laravel为什么在web和中的api数组都没有使用相同的术语Kernel.php。这似乎有点矛盾和混淆使用\Illuminate\Routing\Middleware\SubstituteBindings::class了在web阵列bindings中的api阵列。