uzzal/legacy-router

Legacy router for Laravel framework 5.2+
3,159
Install
composer require uzzal/legacy-router
Latest Version:v1.0.3
PHP:>=5.6.4
License:MIT
Last Updated:Feb 16, 2018
Links: GitHub  ·  Packagist
Maintainer: uzzal

legacy router

Laravel router has been deprecated some features, like Route::controller, and Route::controllers. If your code looks something like the code below then chances are they are no longer supported by the latest versions of the Laravel. To be more precise these feature has been deprecated since laravel 5.2.

This library brings back those legacy route features.

Route::controllers([
    'user'  => 'UserController',        
    'asset/report' => 'Asset\AssetReportController',
    'asset' => 'Asset\AssetController'        
]);

or

Route::controller('/user', 'UserController');

install

composer require uzzal/legacy-router

configure

In your laravel app/Http/Kernel.php add/edit your constructor like that code given below

<?php
namespace App\Http;
...
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
use Uzzal\LegacyRouter\LegacyRouter;
...
class Kernel extends HttpKernel
{

    ...
    
    public function __construct(Application $app)
    {
        $router = new LegacyRouter($app['events'], $app);
        $app->singleton('router', function($app) use ($router){
            return $router;
        });
        parent::__construct($app, $router);
    }

    ...
}

In your laravel app/Console/Kernel.php add/edit your constructor like the code given below make sure you import the

<?php
namespace App\Console;
...
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Uzzal\LegacyRouter\LegacyRouter;
use Illuminate\Contracts\Foundation\Application;
...
class Kernel extends ConsoleKernel
{
    ...    
    public function __construct(Application $app)
    {
        $router = new LegacyRouter($app['events'], $app);
        $app->singleton('router', function($app) use ($router){
            return $router;
        });
        parent::__construct($app, $app['events']);
    }
    ...    
}

That's it. You're done!

what is this (wit)

If you are one of those rare people who don't know how this router worked this part is for you. Imagine you have a controller in your app/Http/Controllers directory like this

class TestController extends Controller
{

    public function getIndex(){
        return 'this is a get request';
    }

    public function postStore(){
        return 'this is a post request';
    }
}

then you can call it using the legacy router like this

Route::controller('/test', 'TestController');

This will automatically mapped with your controller. For more on this take a look at this link implicit-controllers

Related Packages

jasonlewis/enhanced-router

Enhanced Router is an extension to the Laravel 4 router and provides some enhanc...

3,781 149
seytar/php-router

The Laravel router, for use outside of the Laravel framework

588 29
lanin/laravel-hashids

Integrate Hashids with Laravel.

392 10
pecee/simple-router

Simple, fast PHP router that is easy to get integrated and in almost any project...

244,975 670
titzu/cache

Laravel 4 Route Caching

115 11