如何在路由中将两个参数传递到Controller Laravel 6.0中的索引函数

问题描述 投票:0回答:1

*下面,我将让发送两个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的视图,以查看URL是否工作正常

<a href="/eventos/{{$item->id_evento}}/horarios/{{$item->id_horario}}" class="btn btn-dark btn-sm">Horario del evento</a>

*下面,我将让发送两个ID的路由代码,索引函数的代码和尝试时给我的错误代码* Error:LogicException路由模式“ / eventos / {evento} / horarios / {...

php html laravel postgresql
1个回答
0
投票

Route::resource用于基于资源名称创建资源路由。您传递给它的URI的最后一个“段”是资源名称。此资源名称是资源路由所基于的名称。它不能是路径参数(占位符)。

© www.soinside.com 2019 - 2024. All rights reserved.