让我们来看看。
我在laravel中有一个命令:
<?php
namespace App\Console\Commands;
use App\Entity;
use Illuminate\Console\Command;
use Ixudra\Curl\Facades\Curl;
class DownloadIcal extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ical:download';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Download all ICAL files from ical field in businesses database';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$urls = Entity::pluck('ical');
$ids = Entity::pluck('id');
foreach ($urls as $url) {
if($url === null){
print_r("test");
}else{
$response = Curl::to($url);
foreach ($response as $test) {
foreach ($ids as $id) {
>download('public/ical/'.$id.'.ics');
$this->info("ICal Retrieved");
}
}
}
}
}
}
所以我想要做的是检索实体表中的ical列和它属于的id,如果不是null(它是一个url)取值ical,并将其下载为public / ical,其名称为id特定实体。
但是我不确定如何正确地做到这一点。任何人都可以帮助我吗?
答案 0 :(得分:1)
这是你想要完成的事情:
i