*/ class InvoiceFactory extends Factory { /** * Define the model's default state. * * @return array */ public function definition(): array { $payment_status = $this->faker->randomElement(['draft', 'issued', 'paid', 'due', 'reminded']); return [ 'nr' => ($payment_status == 'draft') ? null : $this->faker->unique()->numerify('RE-###'), 'invoice_date' => $this->faker->date(), 'due_date' => $this->faker->date(), 'service_start_date' => $this->faker->date(), 'service_end_date' => $this->faker->date(), 'is_recurring' => $this->faker->boolean(30), 'is_partial_service' => $this->faker->boolean(30), 'customer_id' => Customer::factory(), 'payment_status' => $payment_status, 'total_amount' => $this->faker->randomFloat(2, 100, 1000), 'title' => $this->faker->text(50), 'text' => $this->faker->paragraph(), ]; } /** * Configure the factory to create related line items after creating an invoice. */ public function configure() { return $this->afterCreating(function ($invoice) { LineItem::factory(rand(2, 5))->create([ 'invoice_id' => $invoice->id, ]); }); } }