Package Data | |
---|---|
Maintainer Username: | jrl05k |
Package Create Date: | 2017-04-30 |
Package Last Update: | 2018-07-21 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-15 15:26:01 |
Package Statistics | |
---|---|
Total Downloads: | 5,384 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 4 |
Total Watchers: | 3 |
Total Forks: | 3 |
Total Open Issues: | 0 |
Laravel middleware to display under construction message with an option to login
It's simple. The middleware redirects to the under construction page. This may useful in instances when you want push a release that is still "under construction" to a live server. Then you can use the middleware to display an under construction page to visitors.
If you want to allow certain visitors to be able to see the site you can enable the login option in your .env file.
To make development easier, you can also disable the under construction redirect when the request ip is the localhost. Similarly, when on live server you can disable the under construction message when the request is from certain ip addresses.
You can enable/disable the under construction message for everyone at any point by changing the .env value.
However, when you are ready to go live and no longer need the under construction message, you should remove the middleware from the kernel.
composer require jrl05k/laravel-under-construction
Add UnderConstruction\UnderConstructionProvider::class to config/app.php providers. (only for <5.5.x)
'providers' => [
...
...
/*
* Other Service Providers...
*/
UnderConstruction\UnderConstructionProvider::class,
...
...
It's a simple middleware that will redirect to an "under construction" page.
But, it can be enabled to have a login to bypass the under construction page.
Add \UnderConstruction\RedirectIfUnderConstructionMiddleware::class to Kernel.php middlewareGroups web.
protected $middlewareGroups = [
'web' => [
...
\UnderConstruction\RedirectIfUnderConstructionMiddleware::class
...
You will need to add the following to your .env and set them accordingly
If you want to apply the under construction redirect to certain routes, then instead of putting the middleware in the $middlewareGroups 'web' group, you should put it in the $routeMiddleware array. Then put a route group around the routes you want protected.
Example:
In Kernel.php
$routeMiddleware => [
...
'under-construction' => \UnderConstruction\RedirectIfUnderConstructionMiddleware::class,
...
In routes/web.php
Route::get('/', function () {
return view('welcome');
});
Route::group(['middleware'=>'under-construction'], function() {
// the routes you want protected...
Route::get('/some-page', ...
Route::get('/another-page', ...
...
});
If you want to use a custom under construction page, you can over-ride the views by placing view file in path:
resources/views/vendor/underconstruction/under_construction.blade.php
Likewise, to over-ride the log in create your view in path:
resources/views/vendor/underconstruction/under_construction_login.blade.php
To temporarily turn off the under construction message, you can set the .env UNDER_CONSTRUCTION variable to false.
But to permanently disable it when it is no longer needed for a live production site, you should remove the \UnderConstruction\RedirectIfUnderConstructionMiddleware::class middleware from the Kernel.php. Keeping it in middleware and just disabling it by the .env setting will have a performance cost; so it is best to remove it completely from the Kernel.php middleware.