Skip to content

Commit

Permalink
Implemented validation and checks on community
Browse files Browse the repository at this point in the history
  • Loading branch information
WillTheDeveloper committed Mar 12, 2022
1 parent 0bcdd6a commit 8a03f5c
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/Http/Controllers/Community.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Http\Requests\CreateNewComment;
use App\Http\Requests\CreateNewPost;
use App\Http\Requests\UpdateUserComment;
use App\Http\Requests\UpdateUserPost;
use App\Models\Comment;
use App\Models\Post;
use App\Models\Subject;
Expand Down Expand Up @@ -138,7 +140,7 @@ public function leaveSubject($id) //POST REQUEST
return redirect(route('community'));
}

public function updatePost($id, Request $request)
public function updatePost($id, UpdateUserPost $request)
{
$post = Post::query()->where('posts.id', $id);

Expand All @@ -155,7 +157,7 @@ public function updatePost($id, Request $request)
return redirect(route('community'));
}

public function updateComment($id, Request $request)
public function updateComment($id, UpdateUserComment $request)
{
$comment = Comment::query()->where('comments.id', $id);

Expand Down
30 changes: 30 additions & 0 deletions app/Http/Requests/DeleteUserComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class DeleteUserComment extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}
30 changes: 30 additions & 0 deletions app/Http/Requests/UpdateUserComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateUserComment extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->check() && !auth()->user()->is_banned || auth()->user()->is_admin;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'comment' => ['string', 'min:2', 'max:200']
];
}
}
31 changes: 31 additions & 0 deletions app/Http/Requests/UpdateUserPost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateUserPost extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->check() && !auth()->user()->is_banned || auth()->user()->is_admin;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => ['string', 'min:4', 'max:69'],
'body' => ['string', 'min:2', 'max:200']
];
}
}

0 comments on commit 8a03f5c

Please sign in to comment.