A simple Implicit Router/Controller Router for Laravel whose version >= 5.2 ( 5.5 tested )
A simple Implicit Implicit Router/ Controller Router for Laravel whose version >= 5.2 ( 5.5 tested ), (*1)
CREDIT TO dingo/api and laravel framework, (*2)
(exemple tested working well in Laravel 5.5 / should be the same in Laravel 5.2 5.3 5.4 ), (*3)
From Laravel 5.2, the feature implicit controller routing has been removed., (*4)
But some projects have thousands of routing rules to declare., (*5)
run command:, (*6)
composer require jetwaves/laravel-implicit-router
in your api.php or web.php in routes, add this following lines (1)., (*7)
<?php $api = app('Jetwaves\LaravelImplicitRouter\Router'); $api->controller('URI_PREFIX', 'App\Http\Controllers\TestController');
in your App/Http/Controllers/TestController.php, add a function like, (*8)
<?php public function getShowMeTheMoney(Request $req){ return '10000 gold'; }
then we can access this controller by http://hostname/URI_PREFIX/show-me-the-money and get the following response in your browser. Just like the implicit controller routing of Laravel 5.1 at old time., (*9)
10000 gold
code snippet (1) could be used in a closure of middlewares., (*10)
Route::middleware(['test'])->group(function () { $api = app('Jetwaves\LaravelImplicitRouter\Router'); $api->controller('URI_PREFIX', 'App\Http\Controllers\TestController'); });
when the 'test' middleware do, (*11)
echo 'starcraft tricks :'
and you access http://hostname/URI_PREFIX/show-me-the-money, you'il get, (*12)
starcraft tricks : 10000 gold
in browser., (*13)