added permission for blogPost edit

This commit is contained in:
2024-01-21 19:54:45 +03:00
parent ed65f1bcac
commit 471e857e51
4 changed files with 98 additions and 20 deletions

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Policies;
use App\Models\User;
use App\Models\BlogPost;
class BlogPostPolicy
{
public function edit(User $user, BlogPost $blogPost): bool
{
return $this->isAuthorPlan($user, $blogPost) || $user->hasRole('admin') || $user->hasRole('moderator');
}
private function isAuthorPlan(User $user, BlogPost $blogPost): bool
{
return $user->id === $blogPost->author()->first()->id;
}
}