hcesrl/laravel-wizartisan

构建自定义的 Laravel Artisan 工具命令。

v0.1.0 2019-05-28 10:15 UTC

This package is auto-updated.

Last update: 2024-09-28 22:56:16 UTC


README

Latest Stable Version Total Downloads License

安装

安装包

composer require hcesrl/laravel-wizartisan

用法

创建一个扩展 Wizartisan 命令的向导命令。您必须实现 configureWizard 方法来向向导添加步骤,以及接收经过验证的数据并完成程序的 finish 方法。

<?php
namespace App\Console\Commands;

use Wizartisan\Command;

class CustomCommand extends Command
{
	
	protected function configureWizard ()
	{
		/**
		 * Ask simple question with validation
		 */
		$this->askQuestion ( 'What is your name?' )
			 ->name ( 'name' )
			 ->mustValidate ( 'required' );
		
		/**
		 * Select option from given set
		 */
		$this->askQuestion ( 'Choose your option:' )
			 ->name ( 'option' )
			 ->chooseFrom ( 
			 	[
                    'option1' => 'Option 1',
                    'option2' => 'Option 2',
                    'option3' => 'Option 3',
                ]
		     );
		
		/**
		 * Ask a question with confirmation and hide the answer
		 */
		$this->askQuestion ( 'What is your secret password?' )
			 ->name ( 'password' )
			 ->hideAnswer ()
			 ->withConfirmation ( 'You must confirm your password' );
	}
	
	
	protected function finish ( $data = [] )
	{
		$this->doSomethingWithTheValidInputData ( $data );
		
		return 0;
	}
	
}

许可证

此软件包是开源软件,根据MIT 许可证授权。

作者