Пример #1
0
 public function update($id, EventRequest $request)
 {
     $event = Event::find($id);
     \Session::flash('flash_message1', 'Event was successfully been updated!');
     //$event->update($request->all());
     $event->evt_name = $request->evt_name;
     $event->evt_desc = $request->evt_desc;
     $event->evt_date = $request->evt_date;
     $event->save();
     if ($request->hasFile('image')) {
         $request->file('image')->move(public_path('event'), $request->file('image')->getClientOriginalName());
         $event->image = 'event/' . $request->file('image')->getClientOriginalName();
         $event->save();
     } else {
         dd('No image was found');
     }
     return redirect('events');
 }
Пример #2
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);
 }