Extends DevToolsServiceProvider (Make Laravel look for the DevTools route in the resources folder instead of vendor) #1233
-
Hi I'm working with Laravel Backpack Pro to create an admin panel The thing is i made a lot of changes in my vendor/backpack folder because i wanted the app to be available in english and french (using backpack language switcher). Now i'm publishing what i can so that when i run composer update i don't lose my changes.
I've also copied all the controllers from my vendor to my main controllers file and created, using the cli, a new service provider that extends the DevToolsServiceProvider and i rewrote the method that boots up the route, it looks like this :
But now, how do i modify the code so that laravel points to this service provider instead of the one in my vendor folder ? Theses are screenshots of the logs when i delete one of the controller in the vendor folder (just to see which route file laravel is referring to) : Thank you |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
To make Laravel use your custom service provider instead of the one in the vendor folder, you need to modify your
After making this change, Laravel will use your custom service provider instead of the one in the vendor folder. This means it will use the routes file you specified in your However, I should point out that modifying vendor files directly is generally not recommended, as these changes can be lost when you update your packages. Instead, consider using Backpack's built-in customization features or extending the functionality in your own code without modifying the vendor files. For language localization, Backpack provides a way to add translations without modifying vendor files. You can create language files in your If you need to make more extensive customizations, consider creating your own package that extends Backpack, rather than modifying the vendor files directly. Remember to run Relevant sources: Github Issue (open): [Proposal] Prefix for route names |
Beta Was this translation helpful? Give feedback.
-
Firstly, the providers aren't in config/app.php i don't understand why AI like ChatGPT or Claude keeps telling me that. It is in bootstrap/providers.php Secondly, No the DevTools service provider wasn't inside the bootstrap/providers.php but of course as i used the CLI to create the CustomDevToolsServiceProvider, this one was written in the bootstrap/providers.php Finally, i see in cache/packages.php :
If i modify Also, it seems that the CustomDevtoolsServiceProvider is registered but it happens after the registration of the DevtoolsServiceProvider, so the method to load the routes in the original ServiceProvider is the one that is used and not the one i wrote in my CustomController, and that's the problem |
Beta Was this translation helpful? Give feedback.
-
Ok i found the answer if anyone has the same issue Just go in composer.json of your app and add that
By deactivating the auto discovery, Laravel is not going to infer the service provider of the package even though it is written in it's composer.json, so we can create a new service provider (using the artisan cli so it is registered as provider in bootstrap/providers.php) that extends the service provider of the package to rewrite some methods. Otherwise Laravel registers/boots the default service provider before our customized one so we can't rewrite methods Cheers |
Beta Was this translation helpful? Give feedback.
Ok i found the answer if anyone has the same issue
Just go in composer.json of your app and add that
By deactivating the auto discovery, Laravel is not going to infer the service provider of the package even though it is written in it's composer.json, so we can create a new service provider (using the artisan cli so it is registered as provider in bootstrap/providers.php) that extends the service provider of the package to rewrite some methods. Otherwise Laravel registers/boots the default service provider before our customized one so we can't rewrite methods
Cheers