File size: 5,068 Bytes
907b200
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Award;
use App\Models\Scientist;

class AwardScientistSeeder extends Seeder
{
    public function run(): void
    {
        $relations = [
            [
                'scientist' => 'Alexander Fleming',
                'award' => 'Nobel Prize in Physiology or Medicine',
                'year' => 1945,
                'contribution' => 'Discovery of penicillin and its curative effect in various infectious diseases'
            ],
            [
                'scientist' => 'Paul Ehrlich',
                'award' => 'Nobel Prize in Physiology or Medicine',
                'year' => 1908,
                'contribution' => 'Work on immunity, especially the side-chain theory of antibody formation'
            ],
            [
                'scientist' => 'Gertrude Elion',
                'award' => 'Nobel Prize in Physiology or Medicine',
                'year' => 1988,
                'contribution' => 'Discovery of important principles for drug treatment and development of new drugs'
            ],
            [
                'scientist' => 'Tu Youyou',
                'award' => 'Nobel Prize in Physiology or Medicine',
                'year' => 2015,
                'contribution' => 'Discovery of artemisinin and its use in the treatment of malaria'
            ],
            [
                'scientist' => 'Tu Youyou',
                'award' => 'Lasker Award',
                'year' => 2011,
                'contribution' => 'Clinical medical research for the discovery of artemisinin'
            ],
            [
                'scientist' => 'Kary Mullis',
                'award' => 'Nobel Prize in Physiology or Medicine',
                'year' => 1993,
                'contribution' => 'Invention of the polymerase chain reaction (PCR) method'
            ],
            [
                'scientist' => 'Jonas Salk',
                'award' => 'Lasker Award',
                'year' => 1956,
                'contribution' => 'Development of the poliomyelitis vaccine (euflavac) and its role in the prevention of the disease'
            ],
            [
                'scientist' => 'Selman Waksman',
                'award' => 'Nobel Prize in Physiology or Medicine',
                'year' => 1952,
                'contribution' => 'Discovery of streptomycin, the first antibiotic effective against tuberculosis'
            ],
            [
                'scientist' => 'Emil Fischer',
                'award' => 'Nobel Prize in Physiology or Medicine',
                'year' => 1902,
                'contribution' => 'Work on sugar and purine syntheses, establishing the field of biochemistry'
            ],
            [
                'scientist' => 'Frederick Banting',
                'award' => 'Nobel Prize in Physiology or Medicine',
                'year' => 1923,
                'contribution' => 'Discovery of insulin and its therapeutic value in the treatment of diabetes mellitus'
            ],
            [
                'scientist' => 'Linus Pauling',
                'award' => 'Nobel Prize in Physiology or Medicine',
                'year' => 1954,
                'contribution' => 'Research into the nature of the chemical bond and its application to the structure of complex substances'
            ],
        ];

        $successCount = 0;
        $skipCount = 0;

        foreach ($relations as $rel) {
            try {
                $scientist = Scientist::where('name', $rel['scientist'])->first();
                $award = Award::where('name', $rel['award'])->first();

                if (!$scientist) {
                    $this->command->warn("Scientist not found: {$rel['scientist']}");
                    continue;
                }

                if (!$award) {
                    $this->command->warn("Award not found: {$rel['award']}");
                    continue;
                }

                $exists = $scientist->awards()
                    ->where('award_id', $award->id)
                    ->wherePivot('year_won', $rel['year'])
                    ->exists();

                if ($exists) {
                    $this->command->info("Skipped (exists): {$rel['scientist']}{$rel['award']}");
                    $skipCount++;
                    continue;
                }

                $scientist->awards()->attach($award->id, [
                    'year_won' => $rel['year'],
                    'contribution' => $rel['contribution'],
                ]);

                $this->command->info("Linked: {$rel['scientist']}{$rel['award']} ({$rel['year']})");
                $successCount++;
            } catch (\Exception $e) {
                $this->command->error("Error linking {$rel['scientist']}: " . $e->getMessage());
            }
        }

        $this->command->info('');
        $this->command->info("Summary: {$successCount} linked, {$skipCount} skipped");
        $this->command->info('Award-Scientist relationships completed!');
    }
}