laravel - 自动运行 php artisan ide:models
问题描述
我通过 make:command 创建一个命令
php artisan make:command ResetDBCommand
然后我想在处理程序中运行这两个命令
php artisan ide:models
php artisan db:seed
但是,我无法通过以下代码自动触发这两个命令
Artisan::call('db:seed');
$console->writeln('db:seed done.');
Artisan::call('ide:models--force');
$console->writeln('ide:models done.');
错误:
The command "ide:models--force" does not exist.
我怎样才能做到这一点?
解决方案
正确的命令是ide-helper:models
你可以确认这一点,如果你这样做:
php artisan help ide:models
你得到:
[...]
用法:
ide-helper:models [options] [--] [<model>...]
这表明 Laravel 在命令行中调用时会自动解析该命令。然而,当以编程方式调用它时,这种解析机制并不存在。
另一个问题是这--force
不是一个有效的选项,ide-helper:models
但您可以这样做:
Artisan::call('db:seed');
$console->writeln('db:seed done.');
// Uncomment one of the two
// Artisan::call('ide-helper:models --nowrite'); // Only write metadata in the _ide_helper_models.php file
// Artisan::call('ide-helper:models --write'); // Write metadata on models
// ------
$console->writeln('ide:models done.');
相应地选择您喜欢的任何一个
在 Laravel 8 中测试了上述内容
推荐阅读
- javascript - 用户在网站上传的 SVG 图像的路径
- php - 测试 mysqli 数据库连接是否在最多 5 秒内处于活动状态
- r - scale_x_discrete 和 x 轴定位
- python-3.x - 带有pyLDAvis的Visual Studio中的ipython
- python - 按除数查找开关
- c# - C# 异常处理 finally 块在 catch 块之前
- symfony - 如何访问 base.html.twig 中的 peekAll() 以检查消息/闪烁
- visual-studio-code - 在 VS Code 中选择所有活动的缩进键盘快捷键
- sql - Flattening mutliple Rows into a single row based on identifier
- nginx - 如何在带有 nginx 的 linux 上使用没有 ssl 的 http2.0