Capture Resource route id Checkbox with extra parameter

Asked

Viewed 97 times

0

I have the following route of type Resource:

Route::group(['prefix' => 'processos' ,'namespace' => 'Processos', 'middleware' => 'processo_exists'], function () {

    // Andamentos
    Route::resource('{processo_id}/andamentos', 'AndamentosController');
});

When to access url:

site.com.br/processos/1/andamentos/9

The method show receives a parameter $id, only that it shows the process id (which is number 1), not 9, and the parameter name for the process is {processo_id}, the $id is not the default name for Resource?

  • Can’t be resource in this case, each method has to be configured for each route, and the name is the parameter that must be included in the method. Because actually Resource has a pattern and its route is not in the pattern.

1 answer

2


You also need to specify the parameter for the id at the end

Route::resource('{processo_id}/andamentos/{id}', 'AndamentosController');

there in the show metodo will probably have something like this

function show(Request $res, $processoId, $id){
    echo $processoId;
    echo $id;
}
//site.com.br/processos/1/andamentos/9
//nessa url o trecho acima deve mostar os valores 1 e 9

For more information see the Laravel Docs on routing

  • It gave an error because there is already an implicit {id} but passing the parameters to the method works ok

Browser other questions tagged

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