UserStoreRequest::rules()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 11
nc 2
nop 0
dl 0
loc 18
ccs 0
cts 6
cp 0
crap 6
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
use Illuminate\Validation\Rule;
7
8
class UserStoreRequest 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
     * @return array
24
     */
25
    public function rules()
26
    {
27
        $rules = [
28
            'name' => ['required', 'string', 'max:255'],
29
            'surname' => ['required', 'string', 'max:255'],
30
            'country_id' => ['required', 'string'],
31
            'email' => ['required','string','email','max:255', Rule::unique('users')->ignore($this->id)],
32
            'description' => ['required', 'string'],
33
            'accept_terms' => ['required'],
34
        ];
35
36
        if ($this->getMethod() == 'POST') { //store
37
            $rules += ['password' => 'required'];
38
        } else {
39
            // update
40
        }
41
42
        return $rules;
43
    }
44
}
45