/**
  * 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']);
     }
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(StoreRequest $request)
 {
     $data = $request->all();
     $data['visible'] = true;
     Event::create($data)->tags()->attach($request->tags);
     return redirect('events/admin')->with('message', 'Event created!');
 }