Laravel 5.8 直接添加多个中间件到路由
我正在使用 Laravel 5.8,我有一个这样的路线:
Route::get("certs","CertController@index")->name('certificate.front')->middleware('auth');
现在我想向该路线添加另一个中间件,所以我尝试了这个:
Route::get("certs", "CertController@index")->name('certificate.front')->middleware('prevent-back-history','auth');
现在我没有收到任何错误并且它可以工作但我想知道这种方式是否更好:
Route::get("certs", "CertController@index")->name('certificate.front')->middleware(['prevent-back-history','auth']);
那么在这种情况下哪个更好、更正确?
请注意,我不想使用路由组,并且需要直接向路由指定中间件名称。
I'm using Laravel 5.8 and I have a route like this:
Route::get("certs","CertController@index")->name('certificate.front')->middleware('auth');
Now I wanted to add another middleware to this route, so I tried this:
Route::get("certs", "CertController@index")->name('certificate.front')->middleware('prevent-back-history','auth');
Now I don't get any error and it works But I wonder is this way better or not:
Route::get("certs", "CertController@index")->name('certificate.front')->middleware(['prevent-back-history','auth']);
So which is better and correct in this case?
Note that I don't want to use Route groups and needed to specify the middleware name directly to the route.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后一个代码是正确的方法,因为如果您可以在代码中看到
如果您想要超过特定的 1 个中间件,则应该使用数组来定义中间件,因此使用 [''] 是正确的方法,以防万一您想在路线中添加更多中间件。
The last code is the correct way, because if you can see in your code
If you wanted to have more than specific 1 middleware, you should use an array to define the middleware, so using [''] is the correct way, in case you wanted to add more middleware into the route.
@apose7523
这两种方法都是正确的并且有效,因此选择哪种方法并不重要
@apose7523
Both the approaches are correct and are working, so it does not matter what approach you choose