/** генерирует страницу создания нового теста */ public function create() { $codificator = new Codificator(); $types = []; $sections = []; $query = $codificator->whereCodificator_type('Тип')->select('value')->get(); //формируем массив типов foreach ($query as $type) { array_push($types, $type->value); } $query = $codificator->whereCodificator_type('Раздел')->select('value')->get(); //формируем массив разделов foreach ($query as $section) { array_push($sections, $section->value); } return view('tests.create', compact('types', 'sections')); }
/** AJAX-метод: подгружает интерфейс создания нового вопроса в зависимости от выбранного типа вопроса */ public function getType(Request $request) { if ($request->ajax()) { $type = $request->input('choice'); $query = $this->question->max('id_question'); $id = $query + 1; switch ($type) { case 'Выбор одного из списка': //Стас $codificator = new Codificator(); $sections = []; $query = $codificator->whereCodificator_type('Раздел')->select('value')->get(); foreach ($query as $section) { array_push($sections, $section->value); } return (string) view('questions.teacher.create1', compact('sections')); break; case 'Выбор нескольких из списка': $codificator = new Codificator(); $sections = []; $query = $codificator->whereCodificator_type('Раздел')->select('value')->get(); foreach ($query as $section) { array_push($sections, $section->value); } return (string) view('questions.teacher.create2', compact('sections')); break; case 'Текстовый вопрос': //Стас $codificator = new Codificator(); $sections = []; $query = $codificator->whereCodificator_type('Раздел')->select('value')->get(); foreach ($query as $section) { array_push($sections, $section->value); } return (string) view('questions.teacher.create3', compact('sections')); break; case 'Таблица соответствий': //Миша $codificator = new Codificator(); $sections = []; $query = $codificator->whereCodificator_type('Раздел')->select('value')->get(); foreach ($query as $section) { array_push($sections, $section->value); } return (string) view('questions.teacher.create5', compact('sections')); break; case 'Да/Нет': //Миша $codificator = new Codificator(); $sections = []; $query = $codificator->whereCodificator_type('Раздел')->select('value')->get(); foreach ($query as $section) { array_push($sections, $section->value); } return (string) view('questions.teacher.create4', compact('sections')); break; case 'Определение': $codificator = new Codificator(); $sections = []; $query = $codificator->whereCodificator_type('Раздел')->select('value')->get(); foreach ($query as $section) { array_push($sections, $section->value); } return (string) view('questions.teacher.create7', compact('sections')); break; case 'Просто ответ': $codificator = new Codificator(); $sections = []; $query = $codificator->whereCodificator_type('Раздел')->select('value')->get(); foreach ($query as $section) { array_push($sections, $section->value); } return (string) view('questions.teacher.create8', compact('sections')); break; case 'Теорема': $codificator = new Codificator(); $sections = []; $query = $codificator->whereCodificator_type('Раздел')->select('value')->get(); foreach ($query as $section) { array_push($sections, $section->value); } return (string) view('questions.teacher.create6', compact('sections')); break; } } }