garygreen / pretty-routes

Pretty routes for Laravel
655 stars 77 forks source link

Any way to expose a route file so we can wrap the route in a role controlled route group? #33

Closed ghost closed 6 years ago

ghost commented 7 years ago

I just want to be able to override the default route and wrap this in a route group so that only admin or dev roles can view the /routes page.

ctf0 commented 7 years ago

just edit the url in the config file to the uri ex.admin/routes where only admin or dev have access to it

Braunson commented 7 years ago

@ctf0 How would you apply auth/admin checking middleware to that? I have middleware on anything admin/* but it doesn't apply to /routes since the package is just a custom middleware that displays a view directly.

ctf0 commented 7 years ago

@Braunson i also have the same

https://github.com/garygreen/pretty-routes/blob/3b5967f0bc0c55adfab1905e750f443b2a980d50/config.php#L8

have u tried changing this to admin/routes ?

garygreen commented 7 years ago

I've changed the middleware to a proper route now - reason why it was a middleware before was really for ease of installation and to ensure the route always works, as depending on the order you add the provider in your app.php and what routes are enabled in your app, you may find your app's route overrides pretty routes one. But I've updated the readme instructions to highlight that. Shouldn't be too much of a problem now with autodiscovery.

Also there is a new middlewares config option so you can enable certain middlewares, along with a debug_only option in case you want to expose pretty routes on a production app but only to admins, etc.

Tagged as 1.0.0

Braunson commented 7 years ago

@garygreen You are awesome! 🎉

nhtahoe commented 6 years ago

Not sure why, but any time I added 'auth' to the 'middlewares' in the config/pretty-routes.php I would just get redirected to my app dashboard (actually to login first which would redirect to dashboard since already logged in). So my workaround was to add this to my routes/web.php:

    Route::prefix('admin')->middleware(['web', 'auth', 'dev'])->group(function () {
        Route::get('routes', '\PrettyRoutes\PrettyRoutesController@show');
    });

And this to config/pretty-routes.php:

    'url' => 'admin/routes',

The 'dev' middleware is because I'm using Laravel Spark and that is how you only allow developers