| @@ 18-33 (lines=16) @@ | ||
| 15 | * |
|
| 16 | * @return \Illuminate\Validation\Validator |
|
| 17 | */ |
|
| 18 | public static function create(array $data): Validator |
|
| 19 | { |
|
| 20 | $categories = DiscussCategory::pluckLocked('id'); |
|
| 21 | ||
| 22 | $rules = [ |
|
| 23 | 'title' => 'required|min:5', |
|
| 24 | 'category_id' => [ |
|
| 25 | 'required', |
|
| 26 | 'integer', |
|
| 27 | Rule::in($categories->toArray()) |
|
| 28 | ], |
|
| 29 | 'content' => 'required|min:10' |
|
| 30 | ]; |
|
| 31 | ||
| 32 | return FacadeValidator::make($data, $rules); |
|
| 33 | } |
|
| 34 | ||
| 35 | /** |
|
| 36 | * Get a validator for an incoming update request. |
|
| @@ 43-57 (lines=15) @@ | ||
| 40 | * |
|
| 41 | * @return \Illuminate\Validation\Validator |
|
| 42 | */ |
|
| 43 | public static function update(array $data, int $id): Validator |
|
| 44 | { |
|
| 45 | $categories = DiscussCategory::pluckLocked('id'); |
|
| 46 | ||
| 47 | $rules = [ |
|
| 48 | 'title' => 'required|min:5', |
|
| 49 | 'category_id' => [ |
|
| 50 | 'required', |
|
| 51 | 'integer', |
|
| 52 | Rule::in($categories->toArray()) |
|
| 53 | ] |
|
| 54 | ]; |
|
| 55 | ||
| 56 | return FacadeValidator::make($data, $rules); |
|
| 57 | } |
|
| 58 | } |
|
| 59 | ||