PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, February 26, 2022

[FIXED] How to change route URL in Laravel 9 resource controller

 February 26, 2022     laravel, laravel-9, laravel-routing     No comments   

Issue

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?


Solution

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



Answered By - lagbox
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing