[英]Laravel model:all, use results (collection) in the same function
I am retrieving events from DirtyEvent model and I want to create an Ical using the values from the results however it says that the values do not exist in currect collection: 我正在从DirtyEvent模型中检索事件,我想使用结果中的值创建一个Ical,但是它表示在currect集合中不存在这些值:
public function handle()
{
$event = DirtyEvent::all()
->pluck('startdate')
->pluck('endate');
dd($event);
$vCalendar = new \Eluceo\iCal\Component\Calendar('http://localhost/test');
$vEvent = new \Eluceo\iCal\Component\Event();
$vEvent ->setDtStart(new \DateTime($event->startdate))
->setDtEnd(new \DateTime($event->endate));
$vCalendar->addComponent($vEvent);
dd($vCalendar);
}
DirtyEvent::all()
->pluck('startdate')
->pluck('endate');
What you're doing here is 你在这里做的是
startdate
from the collection of those events startdate
enddate
from the collection of plucked startdates enddate
从弹拨startdates集合 Instead, you should do eg 相反,你应该这样做
DirtyEvent::pluck('startdate', 'enddate')->all();
to get an array of dates, which you can then use to populate your data. 获取日期数组,然后您可以使用它来填充数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.