2017 © Pedro Peláez
 

sdk route-to-controller

A simple Implicit Controller Router for Laravel whose version >= 5.2 ( 5.5 tested )

image

jetwaves/route-to-controller

A simple Implicit Controller Router for Laravel whose version >= 5.2 ( 5.5 tested )

  • Friday, September 8, 2017
  • by jetwaves
  • Repository
  • 1 Watchers
  • 1 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 50 % Grown

The README.md

laravel-implicit-router

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)


HOW TO USE:

(exemple tested working well in Laravel 5.5 / should be the same in Laravel 5.2 5.3 5.4 ), (*3)

Situation:

From Laravel 5.2, the feature implicit controller routing has been removed., (*4)

But some projects have thousands of routing rules to declare., (*5)

Solution:

  1. run command:, (*6)

    composer require jetwaves/laravel-implicit-router
    
  2. 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');
    
  3. in your App/Http/Controllers/TestController.php, add a function like, (*8)

    <?php
    public function getShowMeTheMoney(Request $req){
        return '10000 gold';
    }
    
  4. 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          
  5. All Http method keywords are allowed to be the prefix of Camel Type function name to serve correspondent http methods.
  6. When function does not exists, you'll get a 404 of laravel itself.
  7. Declare explicit routes in the original way. (nothing changed)

Middleware support:

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)

Probably a ungraceful solution but save your time and life. :-)


TODO:

  1. Support some frequently used 'native' middleware declarations, in the line of route declaration.
  2. Beautify the php source code and this readme file.
  3. Make it functional for lumen.
  4. Show me your stars 8-D .

The Versions

08/09 2017

dev-master

9999999-dev

A simple Implicit Controller Router for Laravel whose version >= 5.2 ( 5.5 tested )

  Sources   Download

MIT

by Avatar jetwaves