我设置了一个类,用于删除用户在网页中的项目模型下留下的评论:
<?php
namespace App\Policies;
use App\Comment;
use App\Model_comment;
use App\User;
use App\Post;
class CommentPolicy
{
/**
*
* Defines if User can delete a Comment
*
* @param User $user
* @param Comment $comment
* @param Post $post
* @return bool
*/
public function deleteComment(User $user, Comment $comment, Post $post)
{
return ($user->id === $comment->user_id || $user->id === $post->user_id);
}
/**
* @param User $user
* @param Model_comment $model_comment
* @return bool
*/
public function deleteModelComment(User $user, Model_comment $model_comment)
{
return ($user->id === $model_comment->user_id);
}
}
现在我正在尝试使用它来显示删除评论的按钮。 虽然&#34;删除评论&#34;对于帖子评论工作&#34; deleteModelComment&#34;根本没有通过,没有给出任何错误。 该类在Auth服务提供商下正确注册。 我在刀片视图中调用它,如下所示:
@can('deleteModelComment', $c)
<button id="deletecmnt_{{$c->id}}" class="fa fa-minus pull-right"
aria-hidden="true"
data-token="{{ csrf_token() }}"></button>
@endcan
$ c是Model_comment。任何线索?