
在PHP的框架学习中,我们已经对laravel的安装和配置有所掌握,那么除此之外,在该框架中有一种自带命令,不知道小伙伴们有没有在使用的时候留意过呢?之前没有接触过artisan的也不要着急,本篇就laravel框架自带命令会带来使用的步骤介绍,一起来看看接下来的命令实现吧。
1、作为服务提供者,加载到程序中。
1 2 3 4 5 | 'providers' => [
Illuminate\Foundation\Providers\ArtisanServiceProvider:: class ,
]
|
2、然后找到 Up/Down命令入口
1 2 3 4 5 6 7 8 9 10 11 |
protected function registerUpCommand()
{
$this ->app->singleton( 'command.up' , function () {
return new UpCommand;
});
}
|
3、DownCommand实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | class DownCommand extends Command
{
protected $name = 'down' ;
protected $description = 'Put the application into maintenance mode' ;
public function fire()
{
touch( $this ->laravel->storagePath(). '/framework/down' );
$this ->comment( 'Application is now in maintenance mode.' );
}
}
function touch ( $filename , $time = null, $atime = null) {}
|
以上就是php laravel框架自带命令的实现,相信大家现在对于这种命令已经有所掌握,看完后跟着本篇的教程运行有关的代码即可。更多php学习指路:php框架