У меня возникает следующая ошибка при попытке авторизации некоторых NewsPolicy
:
Слишком мало аргументов для функции App \ Policies \ NewsPolicy :: create (), 1 передано в laravel \ framework \ src \ Осветите \ Auth \ Access \ Gate. php в строке 706 и ожидайте ровно 2
У меня есть модель News
в пространстве имен App\Models
и NewsPolicy
в App\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);
}
}
Но почему моя политика не знает, какую модель они разрешают?