DossierFactory.php
1 <?php 2 3 namespace Database\Factories; 4 5 use App\Enums\EntityTypeEnum; 6 use App\Http\Services\DossierService; 7 use App\Models\ContactInfo; 8 use App\Models\Dossier; 9 use App\Models\DossierMode; 10 use App\Models\DossierType; 11 use App\Models\Entity; 12 use App\Models\Laboratory; 13 use App\Models\TOE; 14 use Illuminate\Database\Eloquent\Factories\Factory; 15 16 class DossierFactory extends Factory 17 { 18 /** 19 * The name of the factory's corresponding model. 20 * 21 * @var string 22 */ 23 protected $model = Dossier::class; 24 25 /** 26 * Define the model's default state. 27 * 28 * @return array 29 */ 30 public function definition() 31 { 32 // $mode = DossierMode::all()->random(); 33 34 return [ 35 'code_year' => date('Y'), 36 'code_seq' => DossierService::getNextCodeByYear(), 37 'dossier_type_id' => DossierType::all()->random()->id, 38 'laboratory_id' => Entity::factory(state: ['entity_type_id' => 1])->has(ContactInfo::factory()), 39 'toe_id' => TOE::factory(), 40 'dossier_status_id' => $this->faker->numberBetween(1, 3), 41 'approved' => $this->faker->boolean, 42 'active' => $this->faker->boolean, 43 'resolved' => $this->faker->boolean, 44 ]; 45 } 46 }