Laravel 中的授权策略参数错误
Authorization Policy argument Error in Laravel
我能用这个做什么:
"Argument 1 passed to App\Policies\NotePolicy::update() must be an
instance of App\Note, instance of App\User given, called in
/Users/acny/Desktop/project/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php
on line 481 (View: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 中写所有东西而不是 'update' 那么我没有错误,但这不是我想要的。
感谢您的帮助
https://laravel.com/docs/5.6/authorization#writing-policies
Laravel 将 $user 作为第一个参数传递。改变你的论点。
我能用这个做什么:
"Argument 1 passed to App\Policies\NotePolicy::update() must be an instance of App\Note, instance of App\User given, called in /Users/acny/Desktop/project/vendor/laravel/framework/src/Illuminate/Auth/Access/Gate.php on line 481 (View:
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 中写所有东西而不是 'update' 那么我没有错误,但这不是我想要的。
感谢您的帮助
https://laravel.com/docs/5.6/authorization#writing-policies
Laravel 将 $user 作为第一个参数传递。改变你的论点。