define a policy for Comments deleting that checks comment author or post author (laravel) -


how can enable both author of post , author of comment delete it? mean, author of posts can delete every comment under posts, while author of comment can delete comments left.

so far have commentpolicy class works this:

class commentpolicy {     public function deletecomment(user $user, comment $comment)     {          return $user->id === $comment->user_id;      }  } 

of course works author of comment. i'm thinking should enable author of posts delete comments in postpolicy class. have there is:

class postpolicy  {      public function seepostoptions(user $user, post $post)     {         return $user->id === $post->user_id;     }   } 

right author of post can see options edit / delete / comment on post. thinking maybe should put 2 @can('deletecomment', $c)<>delete button<>@endcan , @can('seepostoptions' $i)<>delete button<>@endcan result in double button comments left author of post under post.

the solution using @else directive this:

@can('deletecomment', $c) <p>delete</p> @else @can('seepostoptions', $i) <p>delete</p> @endcan @endcan 

Comments