1条回答 默认 最新
- dongya6395 2017-09-29 23:20关注
In a project which follow a "standard project structure"
You must have a class in app/Console named Kernel which extends Illuminate\Foundation\Console\Kernel, an example of how to implement it is as follows:
<?php namespace App\Console; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; class Kernel extends ConsoleKernel { /** * {@inheritdoc} */ protected $commands = [ //here you have to put your commands class ]; /** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule): void { } /** * Register the Closure based commands for the application. * * @return void */ protected function commands(): void { require base_path('routes/console.php'); } }
so now let's create a new command, call it "print" and it will accept a parameter called text, here is the implementation :
<? namespace App\Console\Commands; use Illuminate\Console\Command; class TestCommand extends Command { /** * {@inheritdoc} */ protected $signature = 'test {text}'; /** * {@inheritdoc} */ protected $description = 'Test command.'; /** * {@inheritdoc} */ public function handle() { $this->info($this->argument('text')); } }
as you can see, the new command accept a parameter called text and print it in console.
So to retrieve the parameter sent to an command call, you have to use the argument method in the follow way:
$commandInstance->argument('key_of_parameter');
To get more info read the docs
解决 无用评论 打赏 举报
悬赏问题
- ¥15 求指导ADS低噪放设计
- ¥15 CARSIM前车变道设置
- ¥50 三种调度算法报错 有实例
- ¥15 关于#python#的问题,请各位专家解答!
- ¥200 询问:python实现大地主题正反算的程序设计,有偿
- ¥15 smptlib使用465端口发送邮件失败
- ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
- ¥15 对于squad数据集的基于bert模型的微调
- ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
- ¥20 steam下载游戏占用内存