garygreen / pretty-routes

Pretty routes for Laravel
655 stars 74 forks source link

Added middlewares filtering #48

Closed andrey-helldar closed 4 years ago

andrey-helldar commented 5 years ago

In the current stable version of the package, middlewares are not grouped and, if the middleware is set to null or [], it is not excluded from the final array. Pool request corrects this error.

Before

2018-12-03 14-30-25 sales mercedes andrey avangard local routes - google chrome

After

2018-12-03 14-31-05 sales mercedes andrey avangard local routes - google chrome

Example source

// RouteServiceProvider

protected function mapWebRoutes()
{
    Route::middleware('web')
        ->namespace($this->namespace)
        ->group(base_path('routes/web.php'));
}
// routes

app('router')
    ->middleware('web')
    ->group(function () {

        app('router')
            ->get('foo', 'Auth\LoginController@foo')
            ->middleware(null);

        app('router')
            ->get('bar', 'Auth\LoginController@bar')
            ->middleware([]);

        app('router')
            ->get('baz', 'Auth\LoginController@baz')
            ->middleware('web');

        app('router')
            ->get('baq', 'Auth\LoginController@baq')
            ->middleware([null]);

    });
andrey-helldar commented 4 years ago

I changed my mind about offering middleware filtering by uniqueness.

This is due to the fact that there may be several such checks in the code, but this will not be known with filtering. For example, when each such check makes a request to the database. In my opinion, this is bad.

Therefore, it is better to leave the output of the entire list of middlewares.