问题描述
有没有办法完全禁止artisan命令运行?
例如,如果我想禁止运行PHP artisan migrate:fresh
,我将在哪里删除/禁用该命令?
解决方法
据我所知,laravel默认不具有此功能。而且它仍然在laravel ideas下。
我之前也有此问题,无法找到解决方案,我不确定为什么要禁用命令。但是我的情况是,在production
环境中,我永远不想运行php artisan migrate:fresh
。因此,我最终要覆盖的是默认命令。
例如,在routes/console.php
文件中:
if ('production' === App::environment()) {
Artisan::command('migrate:fresh',function () {
$this->comment('You are not allowed to do this in production!');
})->describe('Override default command in production.');
}
因此,当您进入production
时,php artisan migrate:fresh
将什么也不做。您可以根据自己的要求更改条件,我的示例仅是说明如何根据.env
文件中的某些变量覆盖laravel默认命令。
您也可以在这里做很多事情,我不确定为什么要禁用该命令,所以这是我能提供的最好的帮助。