【问题标题】:Laravel Return Migration and Eloquent ResponseLaravel 返回迁移和 Eloquent 响应
【发布时间】:2021-02-24 10:16:33
【问题描述】:

有没有什么方法可以得到迁移和雄辩的响应或消息?不管成败。

迁移:

$response = Artisan::call('make:model', [
    'name' => 'MyModel'
    '-m' => true
]);
//I need the response for my next step

雄辩:

$response = MyModel::create($myValues);
//I need the response for my next step

【问题讨论】:

  • $response = MyModel::create($myValues);为此,您将获得创建的对象作为响应。
  • @VishalTarkar 有没有办法知道创建时是否有问题,以便我们知道何时回滚到上一个操作。
  • 检查传递给output buffer的内容可能是值得的
  • 当然!有。您可以在 Try Catch 中添加此特定代码。 & 也使用 DB 事务回滚。

标签: laravel laravel-5 eloquent migration


【解决方案1】:

这样使用:

$myModel = new myModel();
$myModel->value = 'value';
$myModel->save(); // you can use create or other function here

现在你的结果是$myModel。与迁移无关。

【讨论】:

  • 如果失败了怎么办?我想知道保存失败的原因。
  • 你的模型和表格是什么?
猜你喜欢
  • 2015-01-29
  • 1970-01-01
  • 1970-01-01
  • 2020-01-12
  • 2013-01-02
  • 2014-11-29
  • 2014-07-30
  • 2021-07-01
  • 2020-02-23
相关资源
最近更新 更多