Download the PHP package divineomega/laravel-route-restrictor without Composer
On this page you can find all versions of the php package divineomega/laravel-route-restrictor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download divineomega/laravel-route-restrictor
More information about divineomega/laravel-route-restrictor
Files in divineomega/laravel-route-restrictor
Package laravel-route-restrictor
Short Description Laravel middleware to restrict a site or specific routes using HTTP basic authentication
License LGPL-3.0-only
Homepage https://github.com/Jord-JD/laravel-route-restrictor
Informations about the package laravel-route-restrictor
🚫 Laravel Route Restrictor
Laravel Route Restrictor is middleware designed to restrict an entire site or specific routes using HTTP Basic Authentication. It is compatible with Laravel 5.1 through 13.
Setup
- Run
composer require jord-jd/laravel-route-restrictor. - On Laravel 5.4 and earlier, add
JordJD\LaravelRouteRestrictor\Providers\LaravelRouteRestrictorServiceProvider::classto the$providersarray in yourconfig/app.phpfile. Newer Laravel versions discover it automatically. - Run
php artisan vendor:publish --provider="JordJD\LaravelRouteRestrictor\Providers\LaravelRouteRestrictorServiceProvider". - Add
\JordJD\LaravelRouteRestrictor\Http\Middleware\BasicAuthentication::classto the$middlewarearray in yourapp/Http/Kernel.phpfile. - Add
'routeRestrictor' => \JordJD\LaravelRouteRestrictor\Http\Middleware\BasicAuthentication::classto the$routeMiddlewarearray in yourapp/Http/Kernel.phpfile. - If a CGI/FastCGI server does not forward the
Authorizationheader, configure the server to forward it. For Apache, addRewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]immediately belowRewriteEngine Oninpublic/.htaccess.
The middleware reads credentials from the request rather than PHP globals, so it also works safely with long-running application servers and test clients.
Global restriction
In order to restrict all routes in your Laravel application, just add the global username and password to your .env file as follows. Ensure you change the username and password values.
Your entire application will then be protected by these details, unless a route specific restriction is in place.
Alternatively, you can modify the global restriction username and password in your config/laravel-route-restrictor.php configuration file.
Restricting specific routes
To restrict specific routes, you must edit your routes file. Simply surround the route or routes you want to restrict with the following route group code. Ensure you change the username and password middleware parameters.
Note: If you have both route specific restrictions and a global restriction, both will work, but route specific restrictions will take priority.
Excluding specific routes from restriction
If you wish to exclude one or more routes from restriction, you must edit your routes file. Simply surround the route or routes you want to exclude with the following route group code.
All versions of laravel-route-restrictor with dependencies
laravel/framework Version ^5.1||^6.0||^7.0||^8.0||^9.0||^10.0||^11.0||^12.0||^13.0