*/ class PianoRateizzazioneFactory extends Factory { protected $model = PianoRateizzazione::class; /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'ripartizione_spese_id' => function () { return RipartizioneSpese::factory()->create()->id; }, 'stabile_id' => function (array $attributes) { if (!empty($attributes['ripartizione_spese_id'])) { $ripartizione = RipartizioneSpese::find($attributes['ripartizione_spese_id']); if ($ripartizione) { return $ripartizione->stabile_id; } } return \App\Models\Stabile::factory()->create()->id; }, 'numero_rate' => 4, 'descrizione' => $this->faker->sentence(), 'importo_totale' => 1000.00, 'data_prima_rata' => now()->addMonth(), 'frequenza' => 'mensile', 'stato' => 'attivo', 'creato_da' => function () { return \App\Models\User::factory()->create()->id; }, ]; } }