fix(auth/admin): atomic user+customer signup; Rule::in for country validation (comma-safe)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
feat/portal-design
nexxo 2026-07-25 18:33:09 +02:00
parent 6ca1e3fba5
commit 22cbe9ac39
3 changed files with 23 additions and 18 deletions

View File

@ -4,6 +4,7 @@ namespace App\Actions\Fortify;
use App\Models\Customer;
use App\Models\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;
@ -39,15 +40,16 @@ class CreateNewUser implements CreatesNewUsers
'password' => $this->passwordRules(),
])->validate();
// Create the user and its linked customer atomically — a public signup is
// a customer, and the portal (Billing::purchase, Settings, …) needs one.
// Either both exist or neither, so a failure never orphans a user.
return DB::transaction(function () use ($input) {
$user = User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
]);
// A public signup is a customer — create and link the record now so the
// portal (Billing::purchase, Settings, …) has a customer to work with
// before they buy a package.
Customer::query()->create([
'user_id' => $user->id,
'name' => $input['name'],
@ -57,5 +59,6 @@ class CreateNewUser implements CreatesNewUsers
]);
return $user;
});
}
}

View File

@ -3,6 +3,7 @@
namespace App\Livewire\Admin;
use App\Models\Datacenter;
use Illuminate\Validation\Rule;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Validate;
use Livewire\Component;
@ -32,7 +33,7 @@ class Datacenters extends Component
$data = $this->validate([
'code' => 'required|string|max:8|alpha_dash|unique:datacenters,code',
'name' => 'required|string|max:255',
'location' => 'nullable|in:'.implode(',', array_keys((array) config('countries'))),
'location' => ['nullable', Rule::in(array_keys((array) config('countries')))],
]);
Datacenter::create([

View File

@ -3,6 +3,7 @@
namespace App\Livewire\Admin;
use App\Models\Datacenter;
use Illuminate\Validation\Rule;
use Livewire\Attributes\Validate;
use LivewireUI\Modal\ModalComponent;
@ -51,7 +52,7 @@ class EditDatacenter extends ModalComponent
}
$data = $this->validate([
'name' => 'required|string|max:255',
'location' => 'nullable|in:'.implode(',', $allowed),
'location' => ['nullable', Rule::in($allowed)], // array form — a legacy value may contain commas
]);
Datacenter::query()->where('uuid', $this->uuid)->update([