【问题标题】:How to run Artisan command without a console如何在没有控制台的情况下运行 Artisan 命令
【发布时间】:2020-09-20 07:49:39
【问题描述】:

有人知道如何在没有控制台的情况下启动命令

让我解释一下 文件下载成功后,需要运行命令php artisan db:seed 我尝试了此选项,但结果出现错误 也许有人知道这个问题的另一种解决方案 我将不胜感激 我尝试了此选项,但结果出现错误

$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
return redirect()->route('admin.accounts');

我试过这个选项

$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
return redirect()->route('admin.accounts');
Artisan::call('db:seed');

还有这个

$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
return redirect()->route('admin.accounts')->with(Artisan::call('db:seed'));

【问题讨论】:

标签: laravel laravel-5 eloquent


【解决方案1】:

我认为这个选项可能有效。但将工匠调用置于回报之上。返回后的任何代码行都将被忽略。

$file = file($request->file->getRealPath());
$fileName = resource_path('upload/csv/accounts/' . date('y-m-d-H-i-s') . '.csv');
$path = file_put_contents($fileName, $file);
Artisan::call('db:seed');// <---- this line 
return redirect()->route('admin.accounts');

【讨论】:

  • 可能是我描述错误的问题我需要console命令才能在redirect之后运行否则文件下载会和console命令并行继续,如果时间长了cloudflare会kill这个过程。
  • 首先,像这样使用重定向发送数据。 stackoverflow.com/questions/25078452/… 然后在控制器中检查数据是否存在。如果数据存在,则运行 artisan 命令。但我认为这不安全。
猜你喜欢
  • 2015-05-01
  • 2019-02-17
  • 2023-03-24
  • 2020-07-10
  • 1970-01-01
  • 1970-01-01
  • 2016-08-18
  • 2021-08-23
  • 2014-04-05
相关资源
最近更新 更多