forked from eatvio/eatvio-infra
20 lines
427 B
PHP
20 lines
427 B
PHP
<?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;
|
|
}
|
|
}
|