Seebad 0.3 stays in this release. With a single landlord every host still reaches the default website. Co-authored-by: Cursor <cursoragent@cursor.com>
43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Users\Pages;
|
|
|
|
use App\Filament\Resources\Users\UserResource;
|
|
use App\Models\User;
|
|
use Filament\Resources\Pages\CreateRecord;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class CreateUser extends CreateRecord
|
|
{
|
|
protected static string $resource = UserResource::class;
|
|
|
|
/**
|
|
* An address that already belongs to another landlord is attached. The account, its password
|
|
* and its two-factor setup stay as they are.
|
|
*
|
|
* @param array<string, mixed> $data
|
|
*/
|
|
protected function handleRecordCreation(array $data): Model
|
|
{
|
|
$email = is_string($data['email'] ?? null) ? $data['email'] : '';
|
|
$existing = User::query()->where('email', $email)->first();
|
|
|
|
if ($existing === null) {
|
|
return parent::handleRecordCreation($data);
|
|
}
|
|
|
|
$attributes = [
|
|
'name' => $data['name'] ?? $existing->name,
|
|
'role' => $data['role'] ?? $existing->role,
|
|
];
|
|
|
|
if (array_key_exists('admin_mode', $data)) {
|
|
$attributes['admin_mode'] = $data['admin_mode'];
|
|
}
|
|
|
|
$existing->forceFill($attributes)->save();
|
|
|
|
return $existing;
|
|
}
|
|
}
|