What is the correct way to pass two or more parameters on the route?

Asked

Viewed 2,003 times

3

I am trying to pass two parameters on the route, however, I get this error:

"Route Pattern "/fiche/{id}/client/{id}" cannot Reference variable name "id" more than Once."

The route used:

Route::get('/visualizar/{ficha_id}/{cliente_id}', 'AnamneseController@visualizar')
->name('visualizar');

Button where the parameter is passed:

<a href="{{route('ficha.visualizar', ['ficha_id' => $f->id, 'cliente_id' => $cliente->id])}}">
    Visualizar Ficha
</a>

Am I doing something wrong? What should I fix?

EDIT All application routes

 Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::group(['as' => 'cadastro.', 'prefix' => 'cadastro'], function () {
    Route::get('/listar', 'CadastroController@index')->name('index');
    Route::get('/adicionar', 'CadastroController@create')->name('adicionar');
    Route::post('/salvar', 'CadastroController@store')->name('salvar');
    Route::get('/{id}/visualizar', 'CadastroController@show')->name('visualizar');
    Route::get('/{id}/editar', 'CadastroController@edit')->name('editar');
});

Route::group(['as' => 'ficha.', 'prefix' => 'ficha'], function () {
    Route::get('/listar', 'AnamneseController@index')->name('index');
    Route::get('/cliente/{id}/adicionar', 'AnamneseController@create')->name('adicionar');
    Route::get('/{id}/cliente/{id}', 'AnamneseController@edit')->name('editar');
    Route::post('/salvar', 'AnamneseController@store')->name('salvar');
    Route::get('/visualizar/{ficha_id}/{cliente_id}', 'AnamneseController@visualizar')->name('visualizar');
});
  • 1

    Try to change ficha_id for fichaId and see what happens.

  • Did you post the right route? The error concerns the route "/ficha/{id}/cliente/{id}" and you posted a route '/visualizar/{ficha_id}/{cliente_id}'.

  • @LINQ switched and changed nothing...

  • @Andregusmao yes, the route is correct. However, no matter what name I put between " { } " remains /ficha/{id}/cliente/{id}

  • Got to put all your routes I think you have routes with problems?

  • @Virgilionovic edited and inserted all routes.

  • Route::get('/{id}/cliente/{id}', 'AnamneseController@edit')->name('editar'); can’t be like that! one of the errors is that it only accepts a variable name per route

  • 2

    Damn life, I was blind wanting to solve the problem of the visualizing route that I didn’t even bother to check the others.. You figured it out here... @Virgilionovic, thanks a lot, man!

Show 3 more comments

3 answers

1

My friend, the error itself already says "cannot Reference variable name "id" more than Once.". You cannot reference the variable name "id" more than once!

0

Good morning!

Just to leave an option, in case you’ve already solved.

It was with the same problem and solved passing an array along with the route associating each value with the respective id.

Ex. ('nome_da_rota',array('fichaID'=>$ficha_id, 'clienteID'=>$cliente_id))

I found in that post.

0

Route::get('/{id}/cliente/{id}', 'AnamneseController@edit')->name('editar');

You have to change this part, you cannot have 2 ids, put {id} and {client}, for example

Browser other questions tagged

You are not signed in. Login or sign up in order to post.