How to rename Http directory 'Controller' in Laravel

How to rename Http directory 'Controller' in Laravel



I am thinking of renaming app/Http directory name to my custom name. Like rename "Http to MyCustomName".



Default Laravel folder:
app/Http/Controllers



After renaming:
app/MyName/Controllers



Can we do that in Laravel?
If yes, then where should I change the namespace and all?





What's your main reason for wanting to change it?
– Ross Wilson
Aug 29 at 17:51




2 Answers
2



You have to change the $namespace inside the Providers/RouteServiceProvider.php so you could stay mention the controller in your routes using the relative format.


$namespace


Providers/RouteServiceProvider.php



Then execute the command :


composer dump-autoload





Already did it. But it won't work.
– webdev
Aug 29 at 8:13





Ok please explain more what you mean by it won't work.
– Zakaria Acharki
Aug 29 at 8:15





@webdev Did you change the namespaces in all the classes in that directory and then run composer dump-autoload?
– Ross Wilson
Aug 29 at 17:53


composer dump-autoload





It worked! Thanks. Forgot to fire command composer dump-autoload.
– webdev
Aug 31 at 6:23



Yes, you can. And you must change namespaces of the all classes which exists in Http folder. And change $namespace property in the RouteServiceProvider.


Http


$namespace


RouteServiceProvider



But this is not a good idea, because Http directory is one of the basic directories of Laravel.


Http






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

PHP code is not being executed, instead code shows on the page

Administrative divisions of China

Cardinality of the set of algorithms