/** * Update or Creates a new event based on Facebook id. * * @param array $attributes * */ public function updateOrCreate($attributes) { $event = Event::where('facebook', '=', $attributes['facebook'])->withHidden()->first(); if (!is_null($event)) { if ($attributes['updated_at'] > $event->updated_at) { $event->update($attributes); echo "Event updated: {$event->name} ({$event->id})\n"; } } else { $attributes['visible'] = true; $event = Event::create($attributes); echo "Event created: {$event->name} ({$event->id})\n"; $event->tags()->attach($attributes['tags']); } }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(DestroyRequest $request, $id) { $event = Event::withHidden()->findOrFail($id); if (count($event->tags)) { $event->tags()->detach($event->tags->lists('id')->toArray()); } $event->delete(); return redirect('events/admin')->with('message', 'Event destroyed.'); }