![](/img/trans.png)
[英]How php artisan migrate command uses Connection.php file?
[英]how can i create a php file that runs php artisan migrate command?
我想在公共目录中创建一个 php 文件,该文件在服务器中运行 php artisan migrate:fresh (--seed) 命令。 当我将我的项目上传到 FTP 服务器时,我想打开该链接(例如: www.project.com/migration.php )并且该文件应该运行迁移和/或种子文件。 如果可以的话,我该怎么做?
顺便说一句,我使用 Laravel 7.28 版本
您可以在函数甚至路由中调用这样的工匠命令!
public function callArtisanCommands()
{
\Artisan::call('cache:clear');
\Artisan::call('view:clear');
\Artisan::call('route:clear');
\Artisan::call('migrate:fresh');
}
创建一个调用 Artisan 命令的路由:
Route::get('migrate', function () {
$exitCode = Artisan::call('migrate:fresh --seed --force');
});
添加了--force
参数,因为在production
环境中需要确认迁移。
有关以编程方式执行命令的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.