laravel-fullcalendar
laravel-fullcalendar copied to clipboard
How to add a url to eloquent events
trafficstars
As in the read me file the following works.
$event = \Calendar::event(
"Valentine's Day", //event title
true, //full day event?
'2015-02-14',
'2015-02-14',
1,
[
'url' => 'http://full-calendar.io',
]
`);
Now I want to add a url to all events pulled from my DB. I tried a couple of things but not working. How can I do it?
$eloquentEvent = Event::all();
foreach($eloquentEvent as $item)
{
$item['url'] = route('event',['id'=>$item['id']]);
//var_dump($item);
// array_push($item, [$item['url'] => route('event',['id'=> $item['id']])]);
}
I'm struggling with this too. I have the calendar displayed successfully, but the title of the events are not linked to their pages.
How can we connect the $value->title with the $value->slug as a link?
Here's the function in my controller:
public function calendar() {
$events = [];
$data = Event::all();
if($data->count()){
foreach ($data as $key => $value) {
$events[] = Calendar::event(
$value->title,
true,
new \DateTime($value->start_date),
new \DateTime($value->end_date.' +1 day')
);
}
}
$calendar = Calendar::addEvents($events);
return view('calendar', compact('calendar'));
}
Anyone with a solution?
$eloquentEvent->map(function ($event) { $event['url'] = route('events.show', $event); return $event; });