Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ConfigurationRequest | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| authorize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| rules | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
6 | |||
| messages | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests; |
| 4 | |
| 5 | use Illuminate\Foundation\Http\FormRequest; |
| 6 | use Illuminate\Validation\Rule; |
| 7 | |
| 8 | class ConfigurationRequest 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 | return true; |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Get the validation rules that apply to the request. |
| 22 | * |
| 23 | * @param $request |
| 24 | * @return array<string, mixed> |
| 25 | */ |
| 26 | public function rules() |
| 27 | { |
| 28 | $data = $this->request->all(); |
| 29 | if (isset($data['parent_id'])) { |
| 30 | return [ |
| 31 | 'name' => ['required', Rule::unique('categories')->where('parent_id', $data['parent_id'])], |
| 32 | 'thumbnail' => 'image|mimes:jpg,jpeg,png,svg', |
| 33 | 'parent_id' => 'nullable', |
| 34 | 'description' => 'nullable', |
| 35 | ]; |
| 36 | } else { |
| 37 | return [ |
| 38 | 'name' => 'required', |
| 39 | 'thumbnail' => 'image|mimes:jpg,jpeg,png,svg', |
| 40 | 'description' => 'nullable', |
| 41 | ]; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | public function messages() |
| 46 | { |
| 47 | return [ |
| 48 | 'name.unique' => 'Plese try another Category Name', |
| 49 | 'name.required' => 'Enter a category Name', |
| 50 | ]; |
| 51 | } |
| 52 | } |