Stelle das U0-Fundament mit CMS, Mitgliedern und Filament bereit.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
89b35ac480
commit
2035c46edd
130 files changed
+18519
-50
No files matched your search
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Domain\Identity\AccountStatus;
|
||||
use App\Domain\Identity\Party;
|
||||
use App\Domain\Identity\PartyType;
|
||||
use App\Domain\Identity\Profile;
|
||||
use App\Domain\Identity\StaffRole;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
protected static ?string $password;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->name(),
|
||||
'email' => fake()->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
'password' => static::$password ??= Hash::make('password'),
|
||||
'status' => AccountStatus::Aktiv,
|
||||
'confirmed_adult_at' => now(),
|
||||
'remember_token' => Str::random(10),
|
||||
];
|
||||
}
|
||||
|
||||
public function configure(): static
|
||||
{
|
||||
return $this->afterMaking(function (User $user): void {
|
||||
if ($user->party_id !== null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$party = Party::query()->create([
|
||||
'type' => PartyType::Person,
|
||||
'display_name' => $user->name,
|
||||
]);
|
||||
|
||||
$user->party_id = $party->id;
|
||||
})->afterCreating(function (User $user): void {
|
||||
Profile::query()->firstOrCreate(
|
||||
['party_id' => $user->party_id],
|
||||
[
|
||||
'display_name' => $user->name,
|
||||
'visibility' => ['display_name' => 'private'],
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function redakteur(): static
|
||||
{
|
||||
return $this->afterCreating(function (User $user): void {
|
||||
$user->staffRoles()->create(['role' => StaffRole::Redakteur]);
|
||||
});
|
||||
}
|
||||
|
||||
public function systemverwalter(): static
|
||||
{
|
||||
return $this->afterCreating(function (User $user): void {
|
||||
$user->staffRoles()->create(['role' => StaffRole::Systemverwalter]);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user