-
app/Policies/Ingredients/IngredientGroupPolicy.php
Open in GitHubuse App\Models\Users\User; use App\Models\Recipes\Recipe; class IngredientGroupPolicy { public function before(User $user, $ability) { if ($user->admin) { return true; } } public function viewAny(?User $user, Recipe $recipe): bool { return !$recipe->cookbook_id || $user->isOwnerOf($recipe->cookbook); } public function view(?User $user, IngredientGroup $ingredientGroup): bool { return true; } // }
-
app/Providers/AuthServiceProvider.php
Open in GitHubuse Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; class AuthServiceProvider extends ServiceProvider { protected $policies = [ // 'App\Models\Ingredients\IngredientGroup' => 'App\Policies\Ingredients\IngredientGroupPolicy', // ]; // }
-
app/Http/Controllers/Ingredients/IngredientGroupController.php
Open in GitHubuse App\Http\Controllers\Controller; use App\Models\Ingredients\IngredientGroup; use App\Http\Requests\Ingredients\IngredientGroup\Store; class IngredientGroupController extends Controller { public function index(Recipe $recipe) { $this->authorize([IngredientGroup::class, $recipe]); return $recipe->ingredientGroups()->get(); } public function store(Recipe $recipe, Store $request) { $this->authorize([IngredientGroup::class, $recipe]); $ingredientGroup = $recipe->ingredientGroups()->create($request->validated()); return $this->responseCreated('ingredient-groups.show', $ingredientGroup->id); } public function create(User $user, Recipe $recipe): bool { return $user->isOwnerOf($recipe); } // }