LaboratorySeeder.php
1 <?php 2 3 namespace Database\Seeders; 4 5 use App\Enums\EntityTypeEnum; 6 use App\Enums\RoleEnum; 7 use App\Enums\UserTypeEnum; 8 use App\Models\Entity; 9 use App\Models\EntityUser; 10 use App\Models\User; 11 use Illuminate\Database\Seeder; 12 use Illuminate\Support\Facades\Hash; 13 14 class LaboratorySeeder extends Seeder 15 { 16 /** 17 * Seed the application's database. 18 * 19 * @return void 20 */ 21 public function run() 22 { 23 $this->addLaboratory(); 24 $this->addApplicant('LinceApplicant'); 25 $this->addApplicant('CCApplicant'); 26 } 27 28 private function addLaboratory() 29 { 30 //Creamos el laboratory JTSEC 31 $laboratory = Entity::factory()->create([ 32 'entity_type_id' => EntityTypeEnum::laboratory()->value, 33 'name' => 'JTSEC', 34 'legal_name' => 'JTSEC', 35 'code' => '', 36 'nif' => '123123123', 37 ]); 38 39 $laboratory->contactInfo()->create([ 40 'address' => 'Constitucoin X', 41 'city' => 'Granada', 42 'postal_code' => '18001', 43 'phone' => '123123123', 44 'email' => 'hello@jtsec.es', 45 'country_id' => null, // TODO: put country in pdf, or make nullable 46 ]); 47 48 $this->addPOC($laboratory, UserTypeEnum::EXTERNAL, RoleEnum::externalCertifier()); 49 } 50 51 private function addPOC(Entity $entity, UserTypeEnum $type, RoleEnum $role) 52 { 53 $user = User::factory()->create(['user_type_id' => $type->value]); 54 $user->entities()->attach($entity->id, ['role_id' => $role->value]); 55 $user->entities()->syncWithPivotValues($entity->id, [ 56 'role_id' => $role->value, 57 'is_poc' => 1, 58 ]); 59 } 60 61 private function addApplicant(string $name) 62 { 63 $applicant = Entity::factory()->create([ 64 'entity_type_id' => EntityTypeEnum::company()->value, 65 'name' => $name, 66 'legal_name' => $name, 67 ]); 68 69 $applicant->contactInfo()->create([ 70 'address' => ' 63008 Efrain Burgs, Grantland, TN 93712', 71 'city' => 'L.A', 72 'postal_code' => '', 73 'phone' => '123123123', 74 'email' => 'poc@' . strtolower($name) . '.es', 75 'country_id' => null, // TODO: put country in pdf, or make nullable 76 ]); 77 78 $this->addPOC($applicant, UserTypeEnum::EXTERNAL, RoleEnum::representative()); 79 $this->addPOC($applicant, UserTypeEnum::EXTERNAL, RoleEnum::evaluator()); 80 } 81 }