Пример #1
0
 public function store(EventRequest $request)
 {
     $user = Auth::user();
     //extract attributes from input
     $attributes = $request->only('name', 'place_name', 'event_type', 'description', 'ticket_cap', 'gmaps_id', 'ticket_price');
     $attributes['ticket_left'] = $request['ticket_cap'];
     $attributes['host_id'] = $user->id;
     // parse date and time to create a carbon instance
     $dateTime = $request['event_date'] . " " . $request['event_time'];
     $attributes['event_time'] = Carbon::createFromFormat('d F, Y H:i', $dateTime);
     // create an Event and associate the user as host
     $event = Event::create($attributes)->host()->associate($user);
     // trim custom tags for whitespace and make array
     $trimmedTags = preg_replace('/\\s+/', '', $request['customTags']);
     $tags = explode(',', $trimmedTags);
     if ($request['tags']) {
         foreach ($request['tags'] as $tag) {
             $event->tags()->attach(Tag::find($tag));
         }
     }
     //
     if ($tags) {
         foreach ($tags as $tag) {
             $event->tags()->attach(Tag::firstOrCreate(array('name' => strtolower($tag))));
         }
     }
     if ($request->file('image')) {
         $imageFile = $request->file('image');
         //make timestamp and append event name for filename
         $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());
         $filename = $timestamp . '-' . $event->name;
         //remove 'image/' from MIME type
         $mime = "." . substr($imageFile->getMimeType(), 6);
         //move file to /public/images/
         $filename = $timestamp . '-' . $event->name;
         $photoData = array('fileName' => $filename, 'mime' => $mime);
         $photo = Photo::create($photoData);
         //move uploaded file to public dir
         $imageFile->move(public_path() . '/images/uploads/', $filename . $mime);
         //associate the image with the user
         $event->photo_id = $photo->id;
         $event->photo()->associate($photo);
         $event->save();
     }
     // Create QR code.
     $code = QrCode::format('png')->size(350)->generate(url('/events') . '/' . $event->id);
     $qrPath = public_path() . '/images/qrcodes/' . $event->id . '.png';
     File::put($qrPath, $code);
     // show all events
     return Redirect::route('events.show', $event);
 }
Пример #2
0
 public function update($id, EventRequest $request)
 {
     $event = Event::withTrashed()->find($id);
     $event->update($request->only(['user_id', 'category_id', 'title', 'subtitle', 'description', 'html', 'annotations', 'genre', 'url_facebook', 'url_wuetix', 'url_tix4gigs', 'scheduled_at', 'time_doors', 'time_start', 'time_end', 'admission', 'price_advance', 'price_advance_discount', 'price_boxoffice', 'price_boxoffice_discount']));
     return $this->respond($event);
 }
Пример #3
0
 /**
  * Store a newly created Member in Database.
  *
  * @param EventRequest $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function store(EventRequest $request)
 {
     $inputs = $request->only(['when', 'image', 'translations']);
     (new Store())->run($inputs);
     return $this->response->created();
 }