Files

53 lines
1.3 KiB
PHP
Raw Permalink Normal View History

2024-08-01 13:53:10 -05:00
<?php
2025-01-28 17:33:54 -06:00
declare(strict_types=1);
2024-08-01 13:53:10 -05:00
namespace App\Actions\Fortify;
use App\Models\User;
2024-10-29 12:38:05 -05:00
use App\Traits\WithTrimStrings;
2024-08-01 13:53:10 -05:00
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Laravel\Fortify\Contracts\CreatesNewUsers;
class CreateNewUser implements CreatesNewUsers
{
use PasswordValidationRules;
2024-10-29 12:38:05 -05:00
use WithTrimStrings;
public function trimExceptions()
{
return ['password'];
}
2024-08-01 13:53:10 -05:00
/**
* Validate and create a newly registered user.
*
* @param array<string, string> $input
*/
public function create(array $input): User
{
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => $this->passwordRules(),
2025-04-09 19:25:15 -05:00
'terms' => config('investbrain.self_hosted') ? '' : ['accepted', 'required'],
2024-08-01 13:53:10 -05:00
])->validate();
2025-04-09 19:25:15 -05:00
$user = User::make([
2024-08-01 13:53:10 -05:00
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
2025-04-09 19:25:15 -05:00
// ensure first user is flagged as an admin
if (User::count() === 0) {
$user->admin = true;
}
$user->save();
return $user;
2024-08-01 13:53:10 -05:00
}
}