larapack / command-verification
使 Artisan 命令在继续前提示控制台。
v1.0.0
2015-11-30 13:33 UTC
This package is auto-updated.
Last update: 2024-09-06 09:19:16 UTC
README
使 Artisan 命令在继续前提示控制台。
安装
使用 composer 安装 composer require larapack/command-verification 1.*
。
用法
首先将 trait Verifiable
添加到您的 Artisan 命令中。
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Larapack/CommandVerification/Verifiable;
class ExampleCommand extends Command
{
use Verifiable;
// ...
}
为了使用户验证是否要运行此命令,您需要将 fire
-方法设置为运行 verify
-方法,并设置 verify
-属性。
protected $verify = 'This command will destroy your entire site!';
public function fire()
{
return $this->verify();
}
如果用户接受,将调用 verified
-方法,所以请确保您已定义它。
public function verified()
{
$this->info('We have destroyed your entire site. Thanks for using our command.');
}
它看起来像这样
自定义
当调用 verify
-方法时,您可以添加以下参数:$this->verify($message, Closure $callback)
public function fire()
{
return $this->verify('A custom verify message', function() {
$this->info('We have destroyed your entire site. Thanks for using our command.');
});
}
这样,您可以重写默认的验证消息和回调。