Я распечатывал 50 вопросов, да, это тоже работало. Но изменилось требование, как брать вопросы по theme_id и распечатывать их по 10 на 10 на 5 страницах. Добрая весть. Я взял theme_id и вопросы. Но как мне получить данные из базы данных в контроллере?
Столбец моей базы данных = вопрос
| id | topic_id |question_text|
| ---|:--------:|:-----------:|
| 1 | 5 | question1 |
| 2 | 6 | question2 |
| 3 | 7 | question3 |
topic_id => запрос количества вопросов
array:9 [▼
"_token" => "N6AJGDf95iQ5WOae3WKibS3yiEdzXJmW7RPXu6sE"
1 => "5"
2 => "3"
3 => "5"
4 => "1"
5 => "3"
6 => "6"
7 => "7"
8 => "8"
]
Это был мой старый контроллер
$questions = $request->input('questions');
$inquiries = $request->input('inquiries');
$queries = $request->input('queries');
$examinations = $request->input('examinations');
$inquisitions = $request->input('inquisitions');
$except = [];
$questions = Question::inRandomOrder()->limit(10)->get();
$except = array_merge($except, $questions->pluck('id')->toArray());
$inquiries = Question::inRandomOrder()->whereNotIn('id', $except)->limit(10)->get();
$except = array_merge($except, $inquiries->pluck('id')->toArray())
$queries = Question::inRandomOrder()->whereNotIn('id', $except)->limit(10)->get();
$except = array_merge($except, $queries->pluck('id')->toArray());
$examinations = Question::inRandomOrder()->whereNotIn('id', $except)->limit(10)->get();
$except = array_merge($except, $examinations->pluck('id')->toArray());
$inquisitions = Question::inRandomOrder()->whereNotIn('id', $except)->limit(10)->get();
foreach ($questions as &$question) {
$question->options = QuestionsOption::where('question_id', $question->id)->inRandomOrder()->get();
}
return view('exams.create', compact('questions','inquiries','queries','examinations','inquisitions'));
create.blade.php
{{ csrf_field() }}
Нэгдүгээр хэсэг
@if(count($questions) > 0)
@foreach($questions as $question)
@if ($i > 1) @endif
Асуулт {{ $question->id }}.
{!! nl2br($question->question_text) !!}
@foreach($question->options as $option)
{{ $option->option }}
@endforeach
@endforeach
@endif
Хоёрдугаар хэсэг
@if(count($inquiries) > 0)
@foreach($inquiries as $question)
@if ($i > 1) @endif
Асуулт {{ $question->id }}.
{!! nl2br($question->question_text) !!}
@foreach($question->options as $option)
{{ $option->option }}
@endforeach
@endforeach
@endif
Гуравдугаар хэсэг
@if(count($queries) > 0)
@foreach($queries as $question)
@if ($i > 1) @endif
Асуулт {{ $question->id }}.
{!! nl2br($question->question_text) !!}
@foreach($question->options as $option)
{{ $option->option }}
@endforeach
@endforeach
@endif
Дөрөвдүгээр хэсэг
@if(count($examinations) > 0)
@foreach($examinations as $question)
@if ($i > 1) @endif
Асуулт {{ $question->id }}.
{!! nl2br($question->question_text) !!}
@foreach($question->options as $option)
{{ $option->option }}
@endforeach
@endforeach
@endif
Тавдугаар хэсэг
@if(count($inquisitions) > 0)
@foreach($inquisitions as $question)
@if ($i > 1) @endif
Асуулт {{ $question->id }}.
{!! nl2br($question->question_text) !!}
@foreach($question->options as $option)
{{ $option->option }}
@endforeach
@endforeach
@endif
Дуусгах
ExamsController@create
вот и все. потому что мне нужно принимать входные запросы массивов вопросов.
@foreach($questions as $question)
@if ($i > 1) @endif
Асуулт {{ $question->id }}.
{!! nl2br($question->question_text) !!}
@foreach($question->options as $option)
{{ $option->option }}
@endforeach
@endforeach
Подробнее здесь: https://stackoverflow.com/questions/495 ... t-10-by-10