forked from eatvio/eatvio-infra
added permission for blogPost edit
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
||||
use App\Models\BlogPost;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
/* use Spatie\QueryBuilder\AllowedFilter; */
|
||||
/* use Spatie\QueryBuilder\QueryBuilder; */
|
||||
@@ -49,6 +50,18 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user