How do I set the url for a route in Laravel?

Asked

Viewed 1,593 times

0

I am using Laravel 5.4 and controllers in Restful standard.

I configured the route file as follows:

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

In view:

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

Na Controller:

public function create() { }

With this, the url of my page:

/entryRegistry/create

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

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

  • What exactly do you want to change?

  • I want to change the text that appears in the browser url

  • but which part? the beginning of Uri is controlled by the first argument passed to the route 'entryRegistry'. Is that the part that bothers you or the create, or the url as a whole?

  • i want to change the entryregistry/create to record-point/create, without changing the controller structure and also without changing the name of the Function and controller in question.

1 answer

1


The idea of using a Route::resource is to standardize all routes of a given resource by following a convention that is documented 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 resetting your routes without using the Route::resource, this way you will 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 this breaks the Restful of the routes.

Read more about how to define your routes and about Resource Controllers in the documentation of Laravel:

Browser other questions tagged

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