0
奇怪的事情。 我设置一个获得3个变量的策略:laravel政策不起作用,感叹是Post没有给出的实例
public function deleteComment(User $user, Comment $comment, Post $post){
//logic
}
然后有一个刀片看法是这样的:
@foreach($posts as $i)
@foreach ($i->comments as $c)
@can('deleteComment', $c, $i)
//show delete button
@endcan
@endforeach
@endforeach
错误返回:的
Argument 3 passed to App\Policies\CommentPolicy::deleteComment() must be an instance of App\Post, none given
而不是显示的按钮。
正如它说你在你的第三个参数中用null调用你的deleteComment函数,它应该是Post的一个实例。添加您调用此函数的代码部分。 – Martin
函数被调用的代码部分就在那里:@can('deleteComment',$ c,$ i) – Chriz74
它不是,@can只能检查用户是否有权访问该函数。你的控制器之间的某处使用deleteComment(),请检查它。 – Martin