@@ -4,8 +4,10 @@ namespace App\Actions\Fortify;
|
||||
|
||||
use App\Concerns\PasswordValidationRules;
|
||||
use App\Concerns\ProfileValidationRules;
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Laravel\Fortify\Contracts\CreatesNewUsers;
|
||||
|
||||
class CreateNewUser implements CreatesNewUsers
|
||||
@@ -22,6 +24,7 @@ class CreateNewUser implements CreatesNewUsers
|
||||
Validator::make($input, [
|
||||
...$this->profileRules(),
|
||||
'password' => $this->passwordRules(),
|
||||
...$this->planRules(),
|
||||
])->validate();
|
||||
|
||||
return User::create([
|
||||
@@ -30,4 +33,26 @@ class CreateNewUser implements CreatesNewUsers
|
||||
'password' => $input['password'],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user