Skip to content

Instantly share code, notes, and snippets.

@devmsh
Last active September 10, 2020 10:08
Show Gist options
  • Save devmsh/2cdd2a9f8eba19271821f7bc55bbd5a1 to your computer and use it in GitHub Desktop.
Save devmsh/2cdd2a9f8eba19271821f7bc55bbd5a1 to your computer and use it in GitHub Desktop.
Easily change laravel routes from strings to static class references
# Easily change laravel routes from strings to static class references
1. Open your route file in your prefered IDE
2. Find and replace using regex
3. Find \'([A-Za-z]*)\@([A-Za-z]*)\'
4. Replace with [App\\Http\\Controllers\\$1::class,'$2']
5. Find \'([A-Za-z]*Controller)\'
6. Replace with App\\Http\\Controllers\\$1::class
5. Done!
# Don't miss to:
1. Remove protected $namespace = 'App\Http\Controllers'; from your RouteServiceProvider
2. Remove the 'namespace' from your route groups
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment