我在嘗試授權某些內容時遇到以下錯誤:NewsPolicy用于運行 App\Policies\NewsPolicy::create() 的參數太少,在 laravel\framework\src\Illuminate\Auth\Access\Gate 中傳遞了 1 個.php在第 706 行,并且恰好在 2 個預期中傳遞我在命名空間下有一個模型,在.NewsApp\ModelsNewsPolicyApp\Policies另外,我在下一個回調中也有自定義:Gate::guessPolicyNamesUsing()AuthServiceProviderGate::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); }}但是,為什么我的保單不知道他們授權的是什么型號呢?
1 回答

千萬里不及你
TA貢獻1784條經驗 獲得超9個贊
好吧,問題是方法根本不需要模型類的第二個參數。viewAnycreate
它應該看起來像這樣:
public function create(User $user)
{
//
}
- 1 回答
- 0 關注
- 84 瀏覽
添加回答
舉報
0/150
提交
取消