|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Actions; |
|
4
|
|
|
|
|
5
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail; |
|
6
|
|
|
use Illuminate\Support\Facades\Validator; |
|
7
|
|
|
use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; |
|
8
|
|
|
use Siak\Tontine\Model\User; |
|
9
|
|
|
|
|
10
|
|
|
class UpdateUserProfile implements UpdatesUserProfileInformation |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Validate and update the given user's profile information. |
|
14
|
|
|
* |
|
15
|
|
|
* @param array<string, string> $input |
|
16
|
|
|
*/ |
|
17
|
|
|
public function update(User $user, array $input): void |
|
18
|
|
|
{ |
|
19
|
|
|
Validator::make($input, [ |
|
20
|
|
|
'name' => ['required', 'string', 'max:255'], |
|
21
|
|
|
'city' => ['nullable', 'string', 'max:100'], |
|
22
|
|
|
'country' => ['required', 'string', 'size:2'], |
|
23
|
|
|
])->validateWithBag('profile'); |
|
24
|
|
|
|
|
25
|
|
|
$user->forceFill([ |
|
26
|
|
|
'name' => $input['name'], |
|
27
|
|
|
])->save(); |
|
28
|
|
|
|
|
29
|
|
|
$user->profile ? $user->profile->fill([ |
|
30
|
|
|
'city' => $input['city'] ?? '', |
|
31
|
|
|
'country_code' => $input['country'], |
|
32
|
|
|
])->save() : $user->profile()->create([ |
|
33
|
|
|
'city' => $input['city'] ?? '', |
|
34
|
|
|
'country_code' => $input['country'], |
|
35
|
|
|
]); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Update the given verified user's profile information. |
|
40
|
|
|
* |
|
41
|
|
|
* @param array<string, string> $input |
|
42
|
|
|
*/ |
|
43
|
|
|
protected function updateVerifiedUser(User $user, array $input): void |
|
44
|
|
|
{ |
|
45
|
|
|
$user->forceFill([ |
|
46
|
|
|
'name' => $input['name'], |
|
47
|
|
|
'email' => $input['email'], |
|
48
|
|
|
'email_verified_at' => null, |
|
49
|
|
|
])->save(); |
|
50
|
|
|
|
|
51
|
|
|
$user->profile ? $user->profile->fill([ |
|
52
|
|
|
'country_code' => $input['country'], |
|
53
|
|
|
])->save() : $user->profile()->create([ |
|
54
|
|
|
'country_code' => $input['country'], |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
$user->sendEmailVerificationNotification(); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|