亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel Policy 方法參數計數的問題

Laravel Policy 方法參數計數的問題

PHP
一只名叫tom的貓 2022-09-03 15:50:28
我在嘗試授權某些內容時遇到以下錯誤: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)

{

    //

}


查看完整回答
反對 回復 2022-09-03
  • 1 回答
  • 0 關注
  • 84 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號