public function update($id, EventFormRequest $request) { $data = (array) $request->all(); $event = $this->event->find($id); if (!$event) { return redirect('/certificates')->withError('Event not found.'); } $data['code'] = $event->code; $event->update($data); if ($event) { return redirect('/certificates/' . $event->id)->with('message', 'Event added.'); } return redirect('/certificates/create')->withError('Event failed.'); }
/** * @param EventRequest $request * @return mixed */ private function createEvent(EventFormRequest $request) { //event (and set status) $data = $request->all(); //Create a slug from the event name $slug = Str::slug($data['name']); $numSlugs = Event::where('slug', '=', $slug)->count(); if ($numSlugs == 0) { $data['slug'] = $slug; } else { $data['slug'] = $slug . "-" . $numSlugs; } //modify the dates with carbon because we're using timedatepicker $data['startDate'] = Carbon::createFromFormat('Y-m-d', $data['startDate'])->format('Y-m-d H:i:s'); $data['endDate'] = Carbon::createFromFormat('Y-m-d', $data['endDate'])->format('Y-m-d H:i:s'); $data['closingDate'] = Carbon::createFromFormat('Y-m-d', $data['closingDate'])->format('Y-m-d H:i:s'); //save the event $event = Auth::user()->events()->create($data); //Upload event image $imageName = $event->id . '.' . $request->file('image')->getClientOriginalExtension(); $request->file('image')->move(base_path() . '/public/img/events/', $imageName); //Insert imageName into the database $event->imageFilename = $imageName; $event->save(); //event tags $this->syncTags($event, $request->input('taglist')); return $event; }