first(); $maths = Subject::where('name', 'Mathematics')->first(); $mathsCourse = Course::where('level_id', $alevel->id) ->where('subject_id', $maths->id) ->first(); if (!$mathsCourse) { $this->command->warn('Maths course not found, skipping ModuleSeeder.'); return; } $modules = [ ['course_id' => $mathsCourse->id, 'name' => 'Pure Mathematics', 'order' => 1], ['course_id' => $mathsCourse->id, 'name' => 'Statistics', 'order' => 2], ]; foreach ($modules as $module) { Module::updateOrCreate( ['course_id' => $module['course_id'], 'name' => $module['name']], $module ); } } }