How to set the url for a route in Laravel?

0

I'm using Laravel 5.4 and controllers in the Restful pattern.

I configured the route file as follows:

Route::resource('entryRegistry', 'EntryRegistryController');

In view:

{{ route('entryRegistry.create') }}

On Controller:

public function create() { }

With this, the url of my page was:

/entryRegistry/create

How do I change the url that references the route of the create function?

I want to change the entryregistry/create to registro-ponto/criar , without changing the structure of the controler and also without changing the name of the function and the controller in question.

    
asked by anonymous 25.03.2017 / 17:22

1 answer

1

The idea of using Route::resource is to standardize all routes for a given resource following a convention that is documented by here:

| Verb      | URI                  | Action  | Route Name     |
|-----------|----------------------|---------|----------------|
| GET       | /photos              | index   | photos.index   |
| GET       | /photos/create       | create  | photos.create  |
| POST      | /photos              | store   | photos.store   |
| GET       | /photos/{photo}      | show    | photos.show    |
| GET       | /photos/{photo}/edit | edit    | photos.edit    |
| PUT/PATCH | /photos/{photo}      | update  | photos.update  |
| DELETE    | /photos/{photo}      | destroy | photos.destroy |

You can change this by redefining your routes without using Route::resource , so you have more control:

Route::get('registro-ponto/criar', 'EntryRegistryController@create')
    ->name('entryRegistry.create');

// Se quiser, pode declarar só a rota de create fora do resource

Route::resource('entryRegistry', 'EntryRegistryController', ['except' => ['create']]);

Keep in mind that doing so breaks RESTful of the routes.

Read more about defining your routes and about Resource Controllers in the Laravel documentation:

25.03.2017 / 18:43