【问题标题】:Authorization Policy argument Error in LaravelLaravel 中的授权策略参数错误
【发布时间】:2018-08-06 06:43:31
【问题描述】:

我能用这个做什么:

"传递给 App\Policies\NotePolicy::update() 的参数 1 必须是 App\Note 的实例,App\User 的实例给定,调用 /Users/acny/Desktop/project/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php 在线481(查看:enter code here /Users/acny/Desktop/project/resources/views/notes/edit.blade.php)"

NotePolicy.php

public function update(Note $note, User $user)
    {
        return $user->id == $note->user_id;
    }

edit.blade.php(用于显示更新按钮):

@can('update', $note)
        <button type="submit" class="btn btn-primary">Update Note</button>
@endcan

如果我在 edit.blade.php 中编写所有内容而不是“更新”,那么我没有错误,但这不是我想要的。
感谢您的帮助

【问题讨论】:

    标签: laravel laravel-5.6


    【解决方案1】:

    https://laravel.com/docs/5.6/authorization#writing-policies

    Laravel 将 $user 作为第一个参数传递。转换你的论点。

    【讨论】:

      猜你喜欢
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-04
      • 2020-06-26
      • 1970-01-01
      相关资源
      最近更新 更多