1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Requests\Profile; |
4
|
|
|
|
5
|
|
|
use App\Infrastructure\Foundation\Http\FormRequest; |
6
|
|
|
use App\Models\User; |
7
|
|
|
use Illuminate\Support\Arr; |
8
|
|
|
use Illuminate\Support\Facades\Auth; |
9
|
|
|
use Illuminate\Validation\Rule; |
10
|
|
|
use Illuminate\Validation\Rules; |
11
|
|
|
|
12
|
|
|
class UpdateRequest extends FormRequest |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* {@inheritDoc} |
16
|
|
|
*/ |
17
|
1 |
|
public function rules() |
18
|
|
|
{ |
19
|
|
|
/** @var \App\Models\User $user */ |
20
|
1 |
|
$user = Auth::user(); |
21
|
|
|
|
22
|
|
|
return [ |
23
|
1 |
|
'username' => ['required', 'string', 'max:255', Rule::unique(User::class)->ignoreModel($user)], |
24
|
|
|
'name' => ['required', 'string', 'max:255'], |
25
|
1 |
|
'email' => ['required', 'string', 'email', 'max:255', Rule::unique(User::class)->ignoreModel($user)], |
26
|
1 |
|
'password' => ['sometimes', 'nullable', 'confirmed', Rules\Password::defaults()], |
27
|
|
|
'bio' => ['sometimes', 'nullable', 'string'], |
28
|
|
|
'is_subscribe_to_newsletter' => ['sometimes', 'boolean'], |
29
|
|
|
]; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritDoc} |
34
|
|
|
*/ |
35
|
1 |
|
public function validated($key = null, $default = null) |
36
|
|
|
{ |
37
|
1 |
|
$validated = parent::validated(); |
38
|
|
|
|
39
|
1 |
|
if ($this->isNotFilled('password')) { |
40
|
|
|
Arr::forget($validated, 'password'); |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
if (!is_null($key)) { |
44
|
|
|
return data_get($validated, $key, $default); |
45
|
|
|
} |
46
|
|
|
|
47
|
1 |
|
return $validated; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|