httpoz / locked
Laravel 包,用于在 x - 日期后锁定应用程序。
v8.0.0
2021-05-13 00:30 UTC
Requires
- php: ^7.3|^8.0
- illuminate/support: ^8.0
Requires (Dev)
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-13 08:09:44 UTC
README
Laravel 包,用于在 x - 日期后锁定应用程序。
Composer
composer require httpoz/locked:^v8.0
配置文件
要将包配置文件发布到您的应用程序中,请在终端中运行此命令。
php artisan vendor:publish --provider="HttpOz\Locked\LockedServiceProvider"
此包允许您定义自己的规则,这些规则将确定使用中间件的路由是否应该被锁定。要开始,请打开 config/locked.php 并将 enabled 设置为 true。接下来,在 rules 数组中列出您的规则类。
规则
您的自定义规则类需要扩展 HttpOz\Locked\Rules\Rule;
<?php use HttpOz\Locked\Rules\Rule; class InActivePeriod extends Rule { /** * The boolean response of this rule is used to determine whether the rule has passed or not. */ public function passes() : bool { return strtotime( 'today' ) >= strtotime('2018-05-31') && strtotime( 'today' ) <= strtotime('2022-05-31'); } }
应用程序将在您的规则返回第一个 false 时被锁定。
中间件
此包包含 IsLocked 中间件。您必须将其添加到 app/Http/Kernel.php 文件中。
<?php /** * The application's route middleware. * * @var array */ protected $routeMiddleware = [ // ... 'isLocked' => \HttpOz\Locked\Middleware\IsLocked::class, ];
现在您可以轻松地保护您的路由。
<?php Route::group(['middleware' => 'isLocked'], function(){ // your routes });
如果逻辑确定应用程序在此时刻被锁定,则抛出 \HttpOz\Locked\Exceptions\ApplicationLocked,这将渲染一个视图。
您可以通过在此处创建文件来覆盖视图 resources\views\vendor\httpoz\locked\locked.blade.php