简体   繁体   中英

How to pass two parameters in a route to an index function in a Controller Laravel 6.0

* Below i will let the code of my route that sends two id's, the code of my index function() and the Error that give me when i tried*

  • Error: LogicException Route pattern "/eventos/{evento}/horarios/{horario}/{{horario}}" cannot reference variable name "horario" more than once.

Route that sends both id's

Route::resource('/eventos/{evento}/horarios/{horario}', 'HorarioeventoController');

This is my 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'));
    }

View that has the href to see if the url works well

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

* Below i will let the code of my route that sends two id's, the code of my index function() and the Error that give me when i tried*

  • Error: LogicException Route pattern "/eventos/{evento}/horarios/{horario}/{{horario}}" cannot reference variable name "horario" more than once.

Route that sends both id's

Route::resource('/eventos/{evento}/horarios/{horario}', 'HorarioeventoController');

This is my 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'));
    }

View that has the href to see if the url works well

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM