$out=[]; DB::table('questions')->where('qa_status','ai_generated')->where('type_id',2)->orderBy('id') ->chunkById(2000, function($rows) use (&$out){ foreach ($rows as $r) { $hasFrac=false; foreach (['answer0','answer1','answer2','answer3'] as $c) { $v=(string)$r->$c; if ($v!=='' && strpos($v,'/')!==false) { $hasFrac=true; break; } } if ($hasFrac) $out[]=['id'=>$r->id,'question'=>$r->question,'answer0'=>$r->answer0,'answer1'=>$r->answer1,'answer2'=>$r->answer2,'answer3'=>$r->answer3,'correct_answer'=>$r->correct_answer,'source'=>$r->source]; } }); file_put_contents(storage_path('app/fib2mcq_all.json'), json_encode($out, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES)); echo "exported=".count($out)."\n";