Files

59 lines
1.5 KiB
PHP
Raw Permalink Normal View History

2026-09-17 23:01:26 -07:00
<?php
namespace App\Actions\Fortify;
use App\Concerns\PasswordValidationRules;
use App\Concerns\ProfileValidationRules;
2026-10-04 20:34:19 -07:00
use App\Models\Organization;
2026-09-17 23:01:26 -07:00
use App\Models\User;
use Illuminate\Support\Facades\Validator;
2026-10-04 20:34:19 -07:00
use Illuminate\Validation\Rule;
2026-09-17 23:01:26 -07:00
use Laravel\Fortify\Contracts\CreatesNewUsers;
class CreateNewUser implements CreatesNewUsers
{
use PasswordValidationRules, ProfileValidationRules;
/**
* Validate and create a newly registered user.
*
* @param array<string, string> $input
*/
public function create(array $input): User
{
Validator::make($input, [
...$this->profileRules(),
'password' => $this->passwordRules(),
2026-10-04 20:34:19 -07:00
...$this->planRules(),
2026-09-17 23:01:26 -07:00
])->validate();
return User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => $input['password'],
]);
}
2026-10-04 20:34:19 -07:00
/**
* Get the validation rules for the chosen plan.
*
* The plan is only required when there is something configured to buy. This
* keeps registration working on a deployment that has not set a Stripe
* price yet, which would otherwise leave nobody able to create an account.
*
* @return array<string, array<int, mixed>>
*/
protected function planRules(): array
{
$plans = array_keys(Organization::availablePlans());
if ($plans === []) {
return [];
}
return [
'plan' => ['required', Rule::in($plans)],
];
}
2026-09-17 23:01:26 -07:00
}