gpt4 book ai didi

laravel-4 - 数据库连接上的 Laravel Artisan 命令

转载 作者:行者123 更新时间:2023-12-05 06:44:46 26 4
gpt4 key购买 nike

我正在从事一个有多个数据库连接的项目。我可以从我的 Controller 运行 artisan 命令,例如 Artisan::call('migrate', array('--path' => 'app/database/migration'));

然而,这在我的默认数据库连接上运行得很好。现在我正在寻找一种方法来为其他动态数据库连接调用 artisan 命令。我知道我可以在命令中指定数据库名称,例如 Artisan::call('migrate', array('--database' => 'myDatabase', '--path' => 'app/database/migration/myCustomMigration')); 但它没有按预期工作。它仍在我的默认数据库连接上运行命令。

有没有办法做到这一点,因为我可以像...一样 Eloquent 地运行工作

$user = new User;
$user->setConnection('myDatabaseConnectionKey');
$user->email = $email;
$user->password = Hash::make('password');
$user->first_name = 'First name';
$user->last_name = 'Last name';
$user->created_at = new DateTime();
$user->updated_at = new DateTime();
$user->save();

提前致谢。

最佳答案

您应该考虑为不同的数据库连接设置不同的环境。然后,您可以使用 --env 标志在该环境中调用任何 artisan 命令。

Laravel Docs for Enviroment Configuration

关于laravel-4 - 数据库连接上的 Laravel Artisan 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27641165/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com