forked from eatvio/eatvio-infra
added permission for blogPost edit
This commit is contained in:
19
app/Policies/RecipePolicy.php
Normal file
19
app/Policies/RecipePolicy.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Recipe;
|
||||
use App\Models\User;
|
||||
|
||||
class RecipePolicy
|
||||
{
|
||||
public function edit(User $user, Recipe $recipe): bool
|
||||
{
|
||||
return $this->isAuthorRecipe($user, $recipe) || $user->hasRole('admin') || $user->hasRole('moderator');
|
||||
}
|
||||
|
||||
private function isAuthorRecipe(User $user, Recipe $recipe): bool
|
||||
{
|
||||
return $user->id === $recipe->author()->first()->id;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user