// Populate answer*_image (and question_image) PATHS for image-option MCQs, // so the front-end references them; the actual drawings are dropped in later // (same workflow as question_image). Idempotent; matches by source. $rows = json_decode(file_get_contents(storage_path('app/_imgopt.json')), true); $upd=0; $notyet=0; foreach ($rows as $r) { $q = DB::table('questions')->where('source',$r['source'])->first(); if (!$q) { $notyet++; continue; } $lvl = strtolower($r['level']); if ($lvl==='?') { continue; } $base = $lvl.'/images/'.$r['slug'].'-q'.$r['n']; $set=[]; for ($k=0;$k<4;$k++){ $a='answer'.$k; if ($q->$a!==null && $q->$a!=='') $set['answer'.$k.'_image']=$base.'-opt'.$k.'.png'; } if (!empty($r['image_needed'])) $set['question_image']=$base.'.png'; if ($set){ $set['updated_at']=now(); DB::table('questions')->where('id',$q->id)->update($set); $upd++; } } echo "imgopt_rows=".count($rows)." updated=$upd not_in_db_yet=$notyet\n";