0

I wondered if there is a way to change the default URLs of Laravel's resource controller. For example, for basic CRUD operation, for creating, we have a /create route made by default by Laravel. Can it be changed to /ask or /new or something like that?

3
  • surely you can, its just a naming convention which you call across your application like on routes or anywhere else. Commented Feb 25, 2022 at 3:50
  • yes, you can extend and bind to the ResourceRegistrar and change anything you want about how the resource routes are defined Commented Feb 25, 2022 at 3:54
  • I am fairy new to laravel and just learning it. It would be very helpful if you could provide me with some code.. Commented Feb 25, 2022 at 4:01

1 Answer 1

4

You can "localize" the resource URIs that are created without much work (Added to the boot method of a Service Provider):

Route::resourceVerbs([
    'create' => 'new',
]);

This would have all calls to Route::resource(...) create the URI with 'new' instead of 'create' for the create action.

If you need to get more complicated than something like that you could extend Illuminate\Routing\ResourceRegistrar to override it in any way you would like. You could call an instance of your version or bind it to the container for Illuminate\Routing\ResourceRegistrar which would use it for all resource calls.

Laravel 9.x - Docs - Controllers - Resource Controllers - Localizing Resource URIs

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.