2025-10-20 08:57:51 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Database\Seeders;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Seeder;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\Customer;
|
|
|
|
|
use App\Models\Contact;
|
2025-11-21 13:23:13 +01:00
|
|
|
use App\Models\Note;
|
2025-10-20 08:57:51 +02:00
|
|
|
use App\Models\Invoice;
|
|
|
|
|
use App\Models\LineItem;
|
|
|
|
|
|
|
|
|
|
class DatabaseSeeder extends Seeder
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Seed the application's database.
|
|
|
|
|
*/
|
|
|
|
|
public function run(): void
|
|
|
|
|
{
|
|
|
|
|
$this->call([
|
|
|
|
|
PaymentTermsSeeder::class,
|
2025-12-02 17:32:52 +01:00
|
|
|
SettingsTableSeeder::class,
|
|
|
|
|
TodoTypeSeeder::class,
|
2025-10-20 08:57:51 +02:00
|
|
|
]);
|
|
|
|
|
|
2025-11-21 13:23:13 +01:00
|
|
|
$user = User::factory()->create([
|
2025-10-20 08:57:51 +02:00
|
|
|
'name' => 'Daniel Stock',
|
|
|
|
|
'email' => 'daniel.stock@tooloop.de',
|
|
|
|
|
'password' => bcrypt('6T0az2JGO5oA'),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Create customers with contacts
|
2025-11-21 13:23:13 +01:00
|
|
|
Customer::factory(20)->create()->each(function ($customer) use ($user) {
|
2025-10-20 08:57:51 +02:00
|
|
|
// Create a primary contact for each customer
|
|
|
|
|
Contact::factory()->create([
|
|
|
|
|
'customer_id' => $customer->id,
|
|
|
|
|
'is_primary' => true,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// Create additional contacts for each customer
|
|
|
|
|
Contact::factory(rand(1, 3))->create([
|
|
|
|
|
'customer_id' => $customer->id,
|
|
|
|
|
]);
|
2025-11-21 13:23:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create some notes for each customer
|
|
|
|
|
Note::factory(rand(0, 5))->create([
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
'customer_id' => $customer->id,
|
|
|
|
|
]);
|
2025-10-20 08:57:51 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Create invoices
|
|
|
|
|
Invoice::factory(20)->create()->each(function ($invoice) {
|
|
|
|
|
// Create line items for each invoice
|
|
|
|
|
LineItem::factory(rand(5, 10))->create([
|
|
|
|
|
'invoice_id' => $invoice->id,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|