shin1x1 / laravel-force-https-url-scheme
Force https url schema middleware for Laravel 5
Installs: 26 570
Dependents: 0
Suggesters: 0
Security: 0
Stars: 25
Watchers: 4
Forks: 3
Open Issues: 2
Requires
- php: >5.4.0
- illuminate/container: ~5.0
- illuminate/http: ~5.0
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: @stable
This package is auto-updated.
Last update: 2024-11-12 19:33:24 UTC
README
Force https url schema middleware for Laravel 5
Install
$ composer require shin1x1/laravel-force-https-url-scheme
Usage
This package provide to redirect http to https. It's implemented Illuminate\Contracts\Routing\Middleware
interface that means you can use it as Laravel middleware. This feature is enabled in production
environments only.
As global HTTP middleware
- app/Http/Kernel.php
<?php namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* @var array
*/
protected $middleware = [
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
'Shin1x1\ForceHttpsUrlScheme\ForceHttpsUrlScheme', // <---added
'Illuminate\Cookie\Middleware\EncryptCookies',
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
'Illuminate\Session\Middleware\StartSession',
'Illuminate\View\Middleware\ShareErrorsFromSession',
'App\Http\Middleware\VerifyCsrfToken',
];}
As route middleware
- app/Http/Kernel.php
<?php namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
(snip)
/**
* The application's route middleware.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => 'App\Http\Middleware\Authenticate',
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
'force_https_url_scheme' => 'Shin1x1\ForceHttpsUrlScheme\ForceHttpsUrlScheme', // <---added
];
}
- app/Http/routes.php
Route::group(['middleware' => 'force_https_url_scheme'], function () {
get('/admin/', function () {
// something here
});
});