【发布时间】:2016-03-03 07:39:19
【问题描述】:
无论我做什么 crud middlware 总是被解雇。但是,只有在声明了 $crud 数组并且仅针对它包含的路由时才应该触发它。但是,并非每次都会触发。即使我说$crud = []; 但是如果我声明['only' => ['route1', 'route2']] 那么它会按预期工作。
<?php
class BaseController extends Controller
{
/**
* Routes which DO NOT load users notifications.
* @var Array Routes without notifications.
*/
public $notifications;
/**
* Routes which DONT require users account to be configured.
* @var Array Routes needing configuration.
*/
public $configured;
/**
* Routes which REQUIRE ownership of resource.
* @var Array CRUD routes.
*/
public $crud;
public function __construct()
{
$this->middleware('auth', ['except' => $this->routes]);
$this->middleware('configured', ['except' => $this->configured]);
$this->middleware('notifications', ['except' => $this->notifications]);
$this->middleware('crud', ['only' => $this->crud]);
}
}
【问题讨论】:
-
提供更多信息。因为在我看来,除了定义的路由之外,“except”确实会触发。这是预期的。如果我理解错了,请进一步解释。
标签: php laravel laravel-5 laravel-routing laravel-middleware