Lravel中的授权策略错误

时间:2018-08-06 06:43:32

标签: laravel laravel-5.6


我该怎么办:

  

“传递给App \ Policies \ NotePolicy :: update()的参数1必须为   App \ Note的实例,给定的App \ User的实例,在   /Users/acny/Desktop/project/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php   在第481行(查看:   /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中写了所有东西而不是'update',那么我没有错误,但是那不是我想要的。
谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

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

Laravel将$ user传递为第一个参数。改变论点。

相关问题