laravel-fullcalendar icon indicating copy to clipboard operation
laravel-fullcalendar copied to clipboard

How to add a url to eloquent events

Open shinokada opened this issue 8 years ago • 2 comments
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']])]);
    }

shinokada avatar Jun 01 '17 06:06 shinokada

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?

emco83 avatar Nov 09 '17 10:11 emco83

$eloquentEvent->map(function ($event) { $event['url'] = route('events.show', $event); return $event; });

dorqa95 avatar Mar 26 '21 15:03 dorqa95