AccountInfoRequest::validationData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Backpack\Base\app\Http\Requests;
4
5
use Illuminate\Foundation\Http\FormRequest;
6
use Illuminate\Validation\Rule;
7
8
class AccountInfoRequest 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
        // only allow updates if the user is logged in
18
        return backpack_auth()->check();
19
    }
20
21
    /**
22
     * Restrict the fields that the user can change.
23
     *
24
     * @return array
25
     */
26
    public function validationData()
27
    {
28
        return $this->only(backpack_authentication_column(), 'name');
29
    }
30
31
    /**
32
     * Get the validation rules that apply to the request.
33
     *
34
     * @return array
35
     */
36
    public function rules()
37
    {
38
        $user = backpack_auth()->user();
39
40
        return [
41
            backpack_authentication_column() => [
42
                'required',
43
                backpack_authentication_column() == 'email' ? 'email' : '',
44
                Rule::unique($user->getTable())->ignore($user->getKey(), $user->getKeyName()),
45
            ],
46
            'name' => 'required',
47
        ];
48
    }
49
}
50