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