-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCreateNewUser.php
51 lines (43 loc) · 1.34 KB
/
CreateNewUser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace App\Actions\Fortify;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
use Laravel\Fortify\Contracts\CreatesNewUsers;
use Ramsey\Uuid\Uuid;
class CreateNewUser implements CreatesNewUsers
{
use PasswordValidationRules;
private const MAX_255 = 'max:255';
/**
* Validate and create a newly registered user.
*
* @param string[] $input
*/
public function create(array $input): User
{
Validator::make($input, [
'first_name' => ['required', 'string', self::MAX_255],
'family_name' => ['required', 'string', self::MAX_255],
'email' => [
'required',
'string',
'email',
'not_regex:/.+@example\.(net|org|com)/',
self::MAX_255,
Rule::unique(User::class),
],
'password' => $this->passwordRules(),
])->validate();
$user = User::create([
'email' => $input['email'],
'first_name' => $input['first_name'],
'family_name' => $input['family_name'],
'password' => Hash::make($input['password']),
'uuid' => Uuid::uuid4(),
]);
$user->giveRole('participant');
return $user;
}
}