Last change
on this file since ff9da8b was 0924b6c, checked in by Özkan İliyaz <iliyaz_96@…>, 4 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Rev | Line | |
---|
[0924b6c] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | namespace App\Http\Requests\Dashboard;
|
---|
| 4 |
|
---|
| 5 | use App\Models\Post;
|
---|
| 6 | use Illuminate\Foundation\Http\FormRequest;
|
---|
| 7 |
|
---|
| 8 | class PostRequest extends FormRequest
|
---|
| 9 | {
|
---|
| 10 | /**
|
---|
| 11 | * Determine if the user is authorized to make this request.
|
---|
| 12 | *
|
---|
| 13 | * @return bool
|
---|
| 14 | */
|
---|
| 15 | public function authorize()
|
---|
| 16 | {
|
---|
| 17 | if($this->isMethod("patch")) {
|
---|
| 18 | $post = Post::find($this->route("id"));
|
---|
| 19 | return auth()->user()->hasPermission("edit_all_posts") || ($post->user->id == auth()->user()->id && $post->is_confirmed);
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | return true;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | /**
|
---|
| 26 | * Get the validation rules that apply to the request.
|
---|
| 27 | *
|
---|
| 28 | * @return array
|
---|
| 29 | */
|
---|
| 30 | public function rules()
|
---|
| 31 | {
|
---|
| 32 | $rules = [
|
---|
| 33 | "title" => "required|min:10|max:255",
|
---|
| 34 | "image" => "required|mimes:jpeg,png,gif|max:5000",
|
---|
| 35 | "category" => "required|integer|exists:categories,id",
|
---|
| 36 | "post_content" => "required|min:100",
|
---|
| 37 | "tags" => "required"
|
---|
| 38 | ];
|
---|
| 39 |
|
---|
| 40 | if($this->isMethod("patch")) {
|
---|
| 41 | $rules["image"] = "mimes:jpeg,png,gif|max:5000";
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | return $rules;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.