Skip to content

Commit

Permalink
adding more validation to user/auth
Browse files Browse the repository at this point in the history
  • Loading branch information
levijackson committed Jun 30, 2021
1 parent bfdb322 commit 1baa676
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function index()

public function create(Request $request)
{
if ($request->user()->canManagePosts()) {
if ($request->user() && $request->user()->canManagePosts()) {
return view('blog.posts.create');
} else {
return redirect('/')
Expand All @@ -50,7 +50,7 @@ public function single(Request $request, string $slug)

public function save(PostRequest $request)
{
if (!$request->user()->canManagePosts()) {
if ($request->user() && !$request->user()->canManagePosts()) {
return redirect('/');
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public function edit(Request $request, string $slug)
{
$post = Post::where('slug', $slug)->first();

if ($post && ($request->user() && $request->user()->id == $post->user_id || $request->user()->isAdmin())) {
if ($post && ($request->user() && ($request->user()->id == $post->user_id || $request->user()->isAdmin()))) {
return view('blog.posts.edit', ['post' => $post]);
}

Expand All @@ -92,12 +92,16 @@ public function edit(Request $request, string $slug)

public function update(PostRequest $request, string $slug)
{
if (!$request->user()->canManagePosts()) {
if (!$request->user() || !$request->user()->canManagePosts()) {
return redirect('/');
}

$post = Post::where('slug', $slug)->first();

if (!$post) {
return redirect('/');
}

$data = $request->validated();

if ($request->has('delete')) {
Expand Down

0 comments on commit 1baa676

Please sign in to comment.