public function questionsbyTopicName($coursename, $subject, $chapterName, $topicName) { $topics = Topic::where('name', $topicName)->get(); $topicID = null; if (count($topics) == 1) { $topicID = $topics->first()->id; } else { $subjects = Course::where('name', $coursename)->first()->subjects()->where('name', $subject)->get(); $questions = collect([]); foreach ($subjects as $subject) { foreach ($subject->modules as $module) { foreach ($module->chapters as $chapter) { if ($chapter->name === $chapterName) { foreach ($chapter->topics as $topic) { if ($topic->name === $topicName) { $topicID = $topic->id; break 4; } } } } } } } return Question::where('topic_id', $topicID); }
public function getfirst($typeid, $uuid) { // to get first element matching based on uuid switch ($typeid) { case 0: //Course return Course::where('id', $uuid)->first(); case 1: //Subject # code... return Subject::where('id', $uuid)->first(); case 2: //Module # code... return Module::where('id', $uuid)->first(); case 3: //Cha[ter] # code... return Chapter::where('id', $uuid)->first(); case 4: //Topic # code... return Topic::where('id', $uuid)->first(); default: # code... break; } }
public function gettopicsbyChapterName() { $subject = Course::where('name', Input::get('course'))->first()->subjects()->where('name', Input::get('subject'))->first(); $modules = $subject->modules; $topicscol = collect([]); foreach ($modules as $module) { foreach ($module->chapters as $chapter) { if ($chapter->name == Input::get('chapter')) { $topicscol->push($chapter->topics); } } } $all_topics = array_values(array_sort($topicscol->flatten(), function ($value) { return $value['no']; })); return $all_topics; }