Files

64 lines
1.7 KiB
PHP

<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Customer;
use App\Models\Contact;
use App\Models\Note;
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,
SettingsTableSeeder::class,
TodoTypeSeeder::class,
UnitSeeder::class,
]);
$user = User::factory()->create([
'name' => 'Daniel Stock',
'email' => 'daniel.stock@tooloop.de',
'password' => bcrypt('6T0az2JGO5oA'),
]);
// Create customers with contacts
Customer::factory(20)->create()->each(function ($customer) use ($user) {
// 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,
]);
// Create some notes for each customer
Note::factory(rand(0, 5))->create([
'user_id' => $user->id,
'notable_id' => $customer->id,
'notable_type' => Customer::class,
]);
});
// 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,
]);
});
}
}