Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

ammannbe/RecipeManager

37 stars
3 code files
View ammannbe/RecipeManager on GitHub

app/Policies/Ingredients/IngredientGroupPolicy.php

Open in GitHub
use 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 GitHub
use 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 GitHub
use 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);
}
//
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.