Good Practices for URI in Restful API using Laravel

Asked

Viewed 160 times

0

Good afternoon,

I’m having to build my routes using the REST standard, but I want to do this using the tools that Laravel offers me, and in the right way. I have the following route to print my service orders:

 ..\ordensdeservico\{id}\impressoes\{tipoImpressao}

It would be correct to use (I’ll just print):

   Route::resource(['ordensdeservico' => "OsController"], function () {
         Route::resource(['impressoes' => "ImpressaoOsController"])->only(['index']);
   });

1 answer

3


To nest a route, \ordensdeservico\{id}\impressoes\{tipoImpressao} for example, Laravel uses 'Nested Resources', an example of how to use the 'Nested Resources':

   Route::resource('ordens_de_servico','OsController');
   Route::resource('ordens_de_servico.impressoes','ImpressaoOsController');

So by default it would call function show() controller’s 'Impresaoontroller', for each REST verb used it would call its respective equivalent method:

inserir a descrição da imagem aqui

The above information was taken from the link: https://laravel.com/docs/5.1/controllers and https://github.com/WhiteHouse/api-standards

Browser other questions tagged

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