I am trying to move the controls I make in the Controller for a User to be able to leave a Comment on another User's Post. The code worked in the Controller but now as I moved it in a Policy I always get a 403 error (Forbidden). This is the policy, it is registered in AuthServiceProvider like :
Comment::class => CommentPolicy::class,
The Policy:
class CommentPolicy
{
public function leaveComment(User $user, Post $post)
{
$following = Follower::where('follower_id', $user->id)->where('publisher_id', $post->user_id)->select('enable_follow')->get();
if (!$following->isEmpty()) {
$enabled = $following[0]['enable_follow'];
if ($enabled != 0) {
return true;
} else {
return false;
}
} else if ($following->isEmpty()) {
return true;
}
}
}
I for the life of me can't understand why in heaven this is not working. In my controller I am passing the $post as
$post = Post::findOrFail($post_id);
$this->authorize('leaveComment', $post);
Does anybody have a clue?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community