|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Database\Seeders; |
| 4 | + |
| 5 | +use Illuminate\Database\Seeder; |
| 6 | +use Illuminate\Support\Facades\DB; |
| 7 | +use Illuminate\Support\Str; |
| 8 | + |
| 9 | +class NodeSeeder extends Seeder |
| 10 | +{ |
| 11 | + public function run(): void |
| 12 | + { |
| 13 | + $subjects = DB::table('subjects')->pluck('id', 'name'); |
| 14 | + |
| 15 | + $data = [ |
| 16 | + 'Higher Math' => [ |
| 17 | + '1st Paper' => [ |
| 18 | + 'Matrix & Determinants', |
| 19 | + 'Vectors', |
| 20 | + 'Straight Lines', |
| 21 | + 'Circle', |
| 22 | + 'Permutations & Combinations', |
| 23 | + 'Trigonometric Ratios & Identities', |
| 24 | + 'Trigonometric Equations & Associated Angles', |
| 25 | + 'Functions & Graphs', |
| 26 | + 'Differentiation', |
| 27 | + 'Integration', |
| 28 | + ], |
| 29 | + '2nd Paper' => [ |
| 30 | + 'Real Numbers & Inequalities', |
| 31 | + 'Polynomials', |
| 32 | + 'Complex Numbers', |
| 33 | + 'Polynomial Equations', |
| 34 | + 'Binomial Theorem', |
| 35 | + 'Conics', |
| 36 | + 'Inverse Trigonometric Functions & Equations', |
| 37 | + 'Statics', |
| 38 | + 'Dynamics / Motion of Particles in a Plane', |
| 39 | + 'Probability & Statistics (Measures of Dispersion)', |
| 40 | + ], |
| 41 | + ], |
| 42 | + |
| 43 | + 'Physics' => [ |
| 44 | + '1st Paper' => [ |
| 45 | + 'Physical World & Measurement', |
| 46 | + 'Vectors', |
| 47 | + 'Motion in a Straight Line', |
| 48 | + 'Newtonian Mechanics', |
| 49 | + 'Work, Energy & Power', |
| 50 | + 'Gravitation', |
| 51 | + 'Properties of Matter', |
| 52 | + 'Waves', |
| 53 | + 'Simple Harmonic Motion', |
| 54 | + 'Thermodynamics', |
| 55 | + ], |
| 56 | + '2nd Paper' => [ |
| 57 | + 'Electrostatics', |
| 58 | + 'Current Electricity', |
| 59 | + 'Magnetic Effects of Current', |
| 60 | + 'Electromagnetic Induction', |
| 61 | + 'AC Circuits', |
| 62 | + 'Modern Physics', |
| 63 | + 'Semiconductor & Electronics', |
| 64 | + 'Communication System', |
| 65 | + ], |
| 66 | + ], |
| 67 | + |
| 68 | + 'Chemistry' => [ |
| 69 | + '1st Paper' => [ |
| 70 | + 'Qualitative Chemistry', |
| 71 | + 'Periodic Table & Periodicity', |
| 72 | + 'Chemical Bonding', |
| 73 | + 'Chemical Changes / Reactions', |
| 74 | + 'Chemistry in Our Life / Environmental Chemistry', |
| 75 | + ], |
| 76 | + '2nd Paper' => [ |
| 77 | + 'Solid State', |
| 78 | + 'Solutions', |
| 79 | + 'Electrochemistry', |
| 80 | + 'Chemical Kinetics', |
| 81 | + 'Organic Chemistry Basics', |
| 82 | + 'Hydrocarbons', |
| 83 | + 'Alcohols, Phenols & Ethers', |
| 84 | + 'Aldehydes, Ketones & Carboxylic Acids', |
| 85 | + 'Amines', |
| 86 | + 'Biomolecules & Applied Chemistry', |
| 87 | + ], |
| 88 | + ], |
| 89 | + |
| 90 | + 'Biology' => [ |
| 91 | + '1st Paper' => [ |
| 92 | + 'Cell Biology', |
| 93 | + 'Cell Division', |
| 94 | + 'Microorganisms', |
| 95 | + 'Algae & Fungi', |
| 96 | + 'Bryophytes & Pteridophytes', |
| 97 | + 'Gymnosperms & Angiosperms', |
| 98 | + 'Plant Physiology', |
| 99 | + ], |
| 100 | + '2nd Paper' => [ |
| 101 | + 'Human Physiology', |
| 102 | + 'Blood & Circulation', |
| 103 | + 'Excretion & Homeostasis', |
| 104 | + 'Nervous System', |
| 105 | + 'Endocrine System', |
| 106 | + 'Reproduction', |
| 107 | + 'Genetics & Evolution', |
| 108 | + 'Ecology & Environment', |
| 109 | + ], |
| 110 | + ], |
| 111 | + ]; |
| 112 | + |
| 113 | + $sort = 0; |
| 114 | + |
| 115 | + foreach ($data as $subjectName => $papers) { |
| 116 | + $subjectId = $subjects[$subjectName] ?? null; |
| 117 | + if (!$subjectId) continue; |
| 118 | + |
| 119 | + foreach ($papers as $paperName => $chapters) { |
| 120 | + |
| 121 | + $paperId = DB::table('nodes')->insertGetId([ |
| 122 | + 'subject_id' => $subjectId, |
| 123 | + 'parent_id' => null, |
| 124 | + 'name' => $paperName, |
| 125 | + 'slug' => Str::slug($paperName), |
| 126 | + 'sort_order' => $sort++, |
| 127 | + 'created_at' => now(), |
| 128 | + 'updated_at' => now(), |
| 129 | + ]); |
| 130 | + |
| 131 | + foreach ($chapters as $index => $chapter) { |
| 132 | + DB::table('nodes')->insert([ |
| 133 | + 'subject_id' => $subjectId, |
| 134 | + 'parent_id' => $paperId, |
| 135 | + 'name' => $chapter, |
| 136 | + 'slug' => Str::slug($chapter), |
| 137 | + 'sort_order' => $index, |
| 138 | + 'created_at' => now(), |
| 139 | + 'updated_at' => now(), |
| 140 | + ]); |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + } |
| 145 | +} |
0 commit comments