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

3

I'm trying to pass two parameters in the route, however, I get this error:

  

"Route pattern" / tab / {id} / client / {id} "can not 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 correct?

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');
});
    
asked by anonymous 28.11.2017 / 16:11

3 answers

0

My friend, the error itself says "can not reference variable name" id "more than once.". You can not reference the variable name "id" more than once!

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

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

    
22.12.2017 / 00:49
0

Good morning!

Just to leave an option, if you have already resolved.

I was having the same problem and I resolved by passing an array along with the route by associating each value with its id.

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

I found in this post .

    
10.07.2018 / 16:34