Merhaba,
En fazla 2.000 üye olacak şekilde ve hepsine rastgele numara verilecek şekilde bu kontrol şekli doğru mu? Test ettim sıkıntı yok gibi ama ileri de patlamaz umarım 😀
public function create(array $input)
{
Validator::make($input, [
'first_name' => ['required', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'email' => [
'required',
'string',
'email:rfc,dns',
'max:255',
Rule::unique(User::class),
],
'password' => $this->passwordRules(),
])->validate();
$memberNumber = rand(100000, 102000);
$user = User::where('member_number', $memberNumber)->first();
if($user) {
for ($i=100000; $i<=102000; $i++) {
$control = User::where('member_number', $i)->first();
if(is_null($control)) {
$memberNumber = $i;
}
}
}
try {
return User::create([
'first_name' => $input['first_name'],
'last_name' => $input['last_name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
'member_number' => $memberNumber
]);
} catch (\Exception $e) {
dd("Leider ist im System kein Platz mehr für Sie frei. Bitte kontaktieren Sie uns.");
}
}