Laravel 5 资源丰富的路由加中间件 [英] Laravel 5 Resourceful Routes Plus Middleware

查看:21
本文介绍了Laravel 5 资源丰富的路由加中间件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将中间件添加到资源丰富的路由的全部或部分项目中?

Is it possible to add middleware to all or some items of a resourceful route?

例如...

<?php

Route::resource('quotes', 'QuotesController');

此外,如果可能的话,我想让除了 indexshow 之外的所有路由都使用 auth 中间件.或者这是否需要在控制器内完成?

Furthermore, if possible, I wanted to make all routes aside from index and show use the auth middleware. Or would this be something that needs to be done within the controller?

推荐答案

QuotesController 构造函数中你可以使用:

In QuotesController constructor you can then use:

$this->middleware('auth', ['except' => ['index','show']]);

参考:Laravel 5 中的控制器中间件

这篇关于Laravel 5 资源丰富的路由加中间件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆