uzzal/legacy-router

Legacy router for Laravel framework 5.2+

v1.0.3 2018-02-16 18:35 UTC

This package is auto-updated.

Last update: 2024-04-22 02:29:10 UTC


README

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