benjaber-98/laravel-https
Composer 安装命令:
composer require benjaber-98/laravel-https
包简介
This is my package LaravelHttps
README 文档
README
Laravel Https is package is created to check for Secure HTTP requests. Laravel Https provides a middleware to force redirection to HTTPS Protocol.
Installation
You can install the package via composer:
composer require benjaber-98/laravel-https
You can publish the config file with:
php artisan vendor:publish
Then choose the number of package service provider from the list.
This is the contents of the published config file:
<?php return [ 'force_in_local' => env('FORCE_HTTPS_IN_LOCAL', false), ];
By default package is disabled in local environment, if you want to turn it on you can set FORCE_HTTPS_IN_LOCAL in .env file like this:
FORCE_HTTPS_IN_LOCAL=true
Usage
Basic Usage:
- Add
\Benjaber98\LaravelHttps\Middlewares\ForceHttpMiddleware::classto your Kernel file like this:
// app/Http/Kernel.php ... //use it globally for all requests protected $middleware = [ ... \Benjaber98\LaravelHttps\Middlewares\ForceHttpMiddleware::class, ]; ... // Or use it globally for all web requests protected $middlewareGroups = [ 'web' => [ ... \Benjaber98\LaravelHttps\Middlewares\ForceHttpMiddleware::class, ], ... //Or register it to use in routes protected $routeMiddleware = [ ... 'force_https' => \Benjaber98\LaravelHttps\Middlewares\ForceHttpMiddleware::class, ];
Route Group Example:
Route::group(['middleware' => ['force_https']], function () { Route::get('/', ['PageController', 'index']); });
Individual Route Examples:
Route::get('/', ['PageController', 'welcome'])->middleware('force_https');
From Controller File:
- You can include the
force_httpsmiddleware in the constructor of your controller file.
Controller File Example:
public function __construct() { $this->middleware('force_https'); }
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 114
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-01