【发布时间】:2021-01-22 21:42:15
【问题描述】:
我想在刀片模板中使用附加参数(在本例中为一系列 ID)循环命名路由。我已经用星号突出显示了我想要在代码中执行此操作的行。我的目的是在单击“下一步”按钮时访问下一页。下一页看起来与前一页完全一样,除了一张不同的问题卡。目前,点击按钮后页面不会发生变化。
这是定义的路线:
Route::get('/quiz/{id}', [QuestionController::class, 'show'])->name("question.show");
这是生成视图的 html 刀片模板。
`@foreach ($questions as $question)
<div class="col-12 col-md-6 my-2 offset-md-3">
<div class="card shadow p-3 mb-5 border bg-warning rounded border">
<h5 class="card-header"> {{ $question->category }} </h5>
<div class="card-body">
<h6 class="card-subtitle mb-2 text-muted">{{ $question->text }}</h6>
@foreach($question->options as $option)
<br>
<input type='radio' name="{{ $question->id }}" value="{{ $option->id }}">
{{ $option->text}} <br>
@endforeach
</div>
**<a href = "{{route('question.show',['id' => $question])}}" class="btn btn-light btn-sm offset-2 offset-md-10" role="button">
Next**
</a>
</div>
</div>
@endforeach`
【问题讨论】: