- Author: Valerio Barbera - [email protected]
- Author Website: www.inspector.dev
Flexible https redirect for Laravel based applications
composer require ilvalerione/laravel-https-redirect
php artisan vendor:publish --provider="Aventure\HttpsRedirect\HttpsRedirectServiceProvider"
This command publish a new configuration file in your config
directory
to list all environment names that you want force to https:
return [
'environments' => [
// 'local', <-- usually no
'development',
'test',
'production',
]
]
Or you can force all possible environment using wildcard:
return [
'environments' => '*'
]
Add HttpsMiddleware
middleware in your global middleware section:
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
...,
\Aventure\HttpsRedirect\Middleware\HttpsCheck::class,
];
...
In alternative you can add middleware as named middleware in your Kernel file:
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $routeMiddleware = [
...,
'https_redirect' => \Aventure\HttpsRedirect\Middleware\HttpsCheck::class,
];
...
And use it programmatically in your routes configuration:
Route::middleware('https_redirect')->group(function(){
Route::view('example', 'example');
});
This package are licensed under the MIT license.