forked from eatvio/eatvio-infra
Merge pull request 'main' (#6) from eatvio/eatvio:main into main
Reviewed-on: maxxkim/eatvio#6
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\BlogPost;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\View\View;
|
||||
|
||||
/* use Spatie\QueryBuilder\AllowedFilter; */
|
||||
@@ -49,6 +50,15 @@ class BlogPostController extends Controller
|
||||
|
||||
public function edit(BlogPost $blogPost): View
|
||||
{
|
||||
if (! $this->canEditBlogPost($blogPost)) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
return view('blog_post/edit_form', ['blogPost' => $blogPost]);
|
||||
}
|
||||
|
||||
private function canEditBlogPost(BlogPost $blogPost): bool
|
||||
{
|
||||
return Gate::allows('edit', $blogPost);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Models\Diet;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\View\View;
|
||||
use Spatie\QueryBuilder\AllowedFilter;
|
||||
use Spatie\QueryBuilder\QueryBuilder;
|
||||
@@ -51,6 +52,10 @@ class DietController extends Controller
|
||||
|
||||
public function edit(Diet $diet): View
|
||||
{
|
||||
if (! $this->canEditDiet($diet)) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
return view('diet/edit_form', ['diet' => $diet]);
|
||||
}
|
||||
|
||||
@@ -64,4 +69,9 @@ class DietController extends Controller
|
||||
|
||||
return view('diet/show', ['diet' => $diet]);
|
||||
}
|
||||
|
||||
private function canEditDiet(Diet $diet): bool
|
||||
{
|
||||
return Gate::allows('edit', $diet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use App\Models\User;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class PlanController extends Controller
|
||||
{
|
||||
@@ -41,6 +42,15 @@ class PlanController extends Controller
|
||||
|
||||
public function edit(Plan $plan): View|ViewFactory
|
||||
{
|
||||
if (! $this->canEditPlan($plan)) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
|
||||
return view('plan/edit_form', ['plan' => $plan]);
|
||||
}
|
||||
|
||||
private function canEditPlan(Plan $plan): bool
|
||||
{
|
||||
return Gate::allows('edit', $plan);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Models\Recipe;
|
||||
use Illuminate\Contracts\View\Factory as ViewFactory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
class RecipeController extends Controller
|
||||
{
|
||||
@@ -37,6 +38,14 @@ class RecipeController extends Controller
|
||||
|
||||
public function edit(Recipe $recipe): View|ViewFactory
|
||||
{
|
||||
if (! $this->canEditRecipe($recipe)) {
|
||||
abort(403, 'Unauthorized action.');
|
||||
}
|
||||
return view('recipe/edit_form', ['recipe' => $recipe]);
|
||||
}
|
||||
|
||||
private function canEditRecipe(Recipe $recipe): bool
|
||||
{
|
||||
return Gate::allows('edit', $recipe);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user