我需要admin
访问控制器中的所有方法,但仅限于某些方法customer-admin
。
我试着用这个
public function __construct()
{
$this->middleware('auth');
$this->middleware('role:customer-admin')->only(['show', 'edit', 'update', 'upload_picture']); // should give access to select methods
$this->middleware('role:admin'); // should give access to all methods
}
但似乎在这种情况下,您必须同时遵守两者。
看起来是反的,在这里你必须基于方法组合角色。所以正确的答案是:
public function __construct()
{
$this->middleware('auth');
$this->middleware('role:customer-admin|admin')->only(['show', 'edit', 'update', 'upload_picture']);
$this->middleware('role:admin')->only(['index', 'create', 'store', 'destroy]); //Indicate methods that are exlusive to admin
}