This script will convert your Laravel 7 compatible routes file to Laravel 8 style.
Yes it is Python. (Python 3)
Do not update your "$namespace" variable of your RoutesServiceProvider before you run this script on your routes. The script will read the root namespace of the RSP.
- Copy the script to your Laravel projects root directory.
- Run the script for each routes file. Example:
python3 laravel-8-route-converter.py routes/web.php
- Control the new route files and copy or replace (with
-r
flag). - Delete the script.
usage: laravel-8-route-converter.py [-h] [-r] routes_file
Convert Laravel 7 to Laravel 8 route file.
positional arguments:
routes_file File to convert.
optional arguments:
-h, --help show this help message and exit
-r, --replace Replace the routes file.
Combinations of all these examples are possible as well.
The script will detect duplicate Controllers (by name) and sets an alias for this controller.
Route::get('/foo/bars', 'FooBarsController@index');
Route::patch('/foo/bars/{bar}', 'FooBarsController@update');
Route::apiResource('/blas', 'BlaController');
Route::resource('/blas', 'BlaController');
Route::apiResource('/foobars', 'FoobarController', ['parameters' => [
'foobars' => 'bar',
]])
->only(['index', 'store', 'destroy',]);
Route::apiResource(
'/foobars',
'FoobarController'
)
->only(['index', 'store', 'destroy',]);
Route::apiResource(
'/foo/bars',
'FooBarsController',
['parameters' => [
'bars' => 'foo',
]]);
Route::group([
'namespace' => 'Bla',
], function () {
Route::patch('/foo/bars/{bar}', 'FooBarsController@update');
Route::group([
'namespace' => 'Tuut',
], function () {
Route::apiResource('/blas', 'BlaController');
});
});