mandant-crm/backend/database/seeders/DatabaseSeeder.php
Tim Stollberg f0bb80707a feat(backend): commit uncommitted CustomField, dynamic HistoryType, and Import modules
Mirrors the frontend catch-up in 570f17e: a substantial amount of
finished-but-never-committed backend work had accumulated locally.

- New CustomField module: admin-managed field definitions per client,
  reorderable, typed values stored per client (backing the frontend's
  ClientCustomFieldCard + settings/fields page)
- History entries switch from a hardcoded type enum to a dynamic,
  admin-managed HistoryType module (reorderable, backing
  settings/history-types)
- New Import module: CSV client import (backing settings/import)
- Clients table gains soft deletes (deleted_at)
- Supporting factories, seeders, policies, and feature tests for all
  of the above

All 63 backend tests pass locally before this commit.
2026-07-18 16:34:18 +07:00

54 lines
2.1 KiB
PHP

<?php
namespace Database\Seeders;
use App\Models\User;
use App\Modules\Client\Models\Client;
use App\Modules\CustomField\Models\CustomFieldDefinition;
use App\Modules\CustomField\Models\CustomFieldType;
use App\Modules\History\Models\HistoryEntry;
use App\Modules\History\Models\HistoryType;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
$admin = User::factory()->create([
'name' => 'Admin',
'email' => 'admin@example.com',
'password' => bcrypt('password'),
'role' => 'admin',
]);
// Base-data custom fields targeted by the Mandanten-Import (idempotent).
$this->call(CustomFieldDefinitionSeeder::class);
// Configurable Verlauf types. Telefonat & Beratungsgespräch carry a
// user-entered event date/time; the rest render as the plain name.
$types = [
['name' => 'Telefonat', 'requires_datetime' => true, 'sort_order' => 1],
['name' => 'Beratungsgespräch', 'requires_datetime' => true, 'sort_order' => 2],
['name' => 'Empfehlung', 'requires_datetime' => false, 'sort_order' => 3],
['name' => 'Anweisung', 'requires_datetime' => false, 'sort_order' => 4],
['name' => 'Bemerkung', 'requires_datetime' => false, 'sort_order' => 5],
['name' => 'Sonstiges', 'requires_datetime' => false, 'sort_order' => 6],
];
$historyTypes = collect($types)->map(fn (array $t) => HistoryType::create($t));
$clients = Client::factory(10)->create();
$clients->each(function (Client $client) use ($admin, $historyTypes) {
$historyTypes->random(3)->each(function (HistoryType $type) use ($client, $admin) {
HistoryEntry::factory()->create([
'client_id' => $client->id,
'author_id' => $admin->id,
'history_entry_type_id' => $type->id,
'occurred_at' => $type->requires_datetime ? now()->subDays(rand(1, 30)) : null,
]);
});
});
}
}