我在尝试授权某些内容时遇到以下错误:NewsPolicy
用于运行 App\Policies\NewsPolicy::create() 的参数太少,在 laravel\framework\src\Illuminate\Auth\Access\Gate 中传递了 1 个.php在第 706 行,并且恰好在 2 个预期中传递
我在命名空间下有一个模型,在.NewsApp\ModelsNewsPolicyApp\Policies
另外,我在下一个回调中也有自定义:Gate::guessPolicyNamesUsing()AuthServiceProvider
Gate::guessPolicyNamesUsing(function ($modelClass) {
return ['\\App\\Policies\\' . class_basename($modelClass) . 'Policy'];
});
我发现Laravel出于某种原因删除了模型类名在:Illuminate\Auth\Access\Gate::callPolicyMethod()
protected function callPolicyMethod($policy, $method, $user, array $arguments)
{
// If this first argument is a string, that means they are passing a class name
// to the policy. We will remove the first argument from this argument array
// because this policy already knows what type of models it can authorize.
if (isset($arguments[0]) && is_string($arguments[0])) {
array_shift($arguments);
}
if (! is_callable([$policy, $method])) {
return;
}
if ($this->canBeCalledWithUser($user, $policy, $method)) {
return $policy->{$method}($user, ...$arguments);
}
}
但是,为什么我的保单不知道他们授权的是什么型号呢?
千万里不及你