让我们开始吧。
我在拉拉维尔有一个命令:
<?php
namespace AppConsoleCommands;
use AppEntity;
use IlluminateConsoleCommand;
use IxudraCurlFacadesCurl;
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,则取一个 ical 值(它是一个 url(并将其下载为公共/ical 并带有名称作为该特定实体的 id。
但是,我不确定如何正确执行此操作。有人可以帮助我吗?
这是您要完成的吗:
$entities = Entity::pluck('ical', 'id');
foreach ( $entities as $entityID => $entityIcal ) {
$response = Curl::to($entityIcal);
foreach ($response as $test) {
>download('public/ical/'.$entityID.'.ics');
$this->info("ICal Retrieved");
}
}