<p>I got help on Discord. The way to do it was <code>Calendar::getInstance()-&gt;events-&gt;saveEvent($event);</code> Edit: <code>DateTime</code> also needs to be replaced with <code>Carbon()</code></p>

CC BY-SA 4.0
2020-10-21T08:42:15.053Z
2020-10-21T16:29:13.167Z
2020-10-21T16:29:13.167Z
Stian Karlsen
<p>I'm trying to create an event from within a plugin. I've come up with the following:</p>
<pre><code>$event = new Event(); // Solspace\Calendar\Elements\Event;
$event-&gt;authorId = 1;
$event-&gt;calendarId = 5;
$event-&gt;name = 'Hello name';
$event-&gt;title = 'Hello title';
$event-&gt;startDate = new DateTime();
$event-&gt;endDate = new DateTime();
$event-&gt;allDay = true;
</code></pre>
<p>But I don't understand how to actually save the event (e.g. <code>$event-&gt;save()</code>). Am I on the right track or completely off? I couldn't find anything on this in the docs.</p>

<plugin-development><plugin-solspacecalendar>
Creating a calendar event from within a plugin (stuck on saving)
# Creating a calendar event from within a plugin (stuck on saving)

(Asked by: username_0 on 2020-10-20)

I'm trying to create an event from within a plugin. I've come up with the following:
$event = new Event(); // Solspace\Calendar\Elements\Event;
$event->authorId = 1;
$event->calendarId = 5;
$event->name = 'Hello name';
$event->title = 'Hello title';
$event->startDate = new DateTime();
$event->endDate = new DateTime();
$event->allDay = true;

But I don't understand how to actually save the event (e.g. $event->save()). Am I on the right track or completely off? I couldn't find anything on this in the docs.

**Tags:** plugin-development, plugin-solspacecalendar


---

## 1 answers

### Answer by username_0 on 2020-10-21. Score: 2 | Accepted answer

I got help on Discord. The way to do it was `Calendar::getInstance()->events->saveEvent($event);` Edit: `DateTime` also needs to be replaced with `Carbon()`


---

