[英]How to pass two parameters in a route to an index function in a Controller Laravel 6.0
*在下面,我将让发送两个ID的路线代码,我的index function()
代码和尝试时给我的错误代码*
LogicException Route pattern "/eventos/{evento}/horarios/{horario}/{{horario}}" cannot reference variable name "horario" more than once.
发送两个ID的路由
Route::resource('/eventos/{evento}/horarios/{horario}', 'HorarioeventoController');
这是我的Index function()
public function index(Request $request, $id, $id2)
{
$horario_evento = DB::select(DB::raw("SELECT id_horario_evento, fk_evento,fk_horario, (
SELECT nombre_evento FROM evento WHERE id_evento = fk_evento ),(SELECT dia FROM horario WHERE id_horario = fk_horario )
FROM horario_evento WHERE fk_evento = '$id' and fk_horario='$id2' "));
return view ('home.horario_evento', compact('horario_evento'));
}
带有href的视图,以查看该网址是否运作良好
<a href="/eventos/{{$item->id_evento}}/horarios/{{$item->id_horario}}" class="btn btn-dark btn-sm">Horario del evento</a>
*在下面,我将让发送两个ID的路线代码,我的index function()
代码和尝试时给我的错误代码*
LogicException Route pattern "/eventos/{evento}/horarios/{horario}/{{horario}}" cannot reference variable name "horario" more than once.
发送两个ID的路由
Route::resource('/eventos/{evento}/horarios/{horario}', 'HorarioeventoController');
这是我的Index function()
public function index(Request $request, $id, $id2)
{
$horario_evento = DB::select(DB::raw("SELECT id_horario_evento, fk_evento,fk_horario, (
SELECT nombre_evento FROM evento WHERE id_evento = fk_evento ),(SELECT dia FROM horario WHERE id_horario = fk_horario )
FROM horario_evento WHERE fk_evento = '$id' and fk_horario='$id2' "));
return view ('home.horario_evento', compact('horario_evento'));
}
带有href的视图,以查看该网址是否运作良好
<a href="/eventos/{{$item->id_evento}}/horarios/{{$item->id_horario}}" class="btn btn-dark btn-sm">Horario del evento</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.