Ejemplo n.º 1
0
 public function addActivityMedia(Request $request, $activityId)
 {
     if (!$request->hasFile('file')) {
         return Response::json(['error' => 'No File Sent']);
     }
     if (!$request->file('file')->isValid()) {
         return Response::json(['error' => 'File is not valid']);
     }
     $file = $request->file('file');
     $v = Validator::make($request->all(), ['file' => 'required|mimes:jpeg,jpg,png|max:8000']);
     if ($v->fails()) {
         return Response::json(['error' => $v->errors()]);
     }
     $image = $this->processImageUpload($request);
     //return Response::json(['OK' => 1, 'filename' => $filename, 'media_id' => $image->id]);
     DB::transaction(function () use($request, $image, $activityId) {
         $activityMedia = ActivityMedia::firstOrCreate(['media_id' => $image->id, 'activity_id' => $activityId]);
     });
     return Response::json(['OK' => 1, 'filename' => $image->name, 'media_id' => $image->id]);
 }
Ejemplo n.º 2
0
 public function update(Request $request, $id)
 {
     $activity = Activity::find($id);
     DB::transaction(function () use($request, $activity) {
         if ($request->has('location')) {
             $pregeo = $request->input('location');
             if (isset($pregeo['address_components'])) {
                 $geo = $this->processGeoValue($pregeo);
                 $location = Location::firstOrCreate($geo);
                 $location->save();
                 $activity->location_id = $location->id;
             }
         }
         $activity->title = $request->input('title');
         $activity->description = $request->input('description');
         $activity->details = $request->input('details');
         $activity->main_picture = $request->input('main_picture');
         $arr = explode(".", $request->input('event_date'), 2);
         $event_date = str_replace("T", " ", $arr[0]);
         $activity->event_date = Carbon::createFromFormat('Y-m-d H:i:s', $event_date);
         $activity->twitter_hashtag = $request->input('twitter_hashtah');
         $activity->instagram_hashtag = $request->input('instagram_hashtag');
         $activity->organization_id = $request->input('organization_id');
         $activity->center_id = $request->input('center_id');
         $activity->coordinators = $request->input('coordinators');
         $activity->place = $request->input('place');
         $categories = $request->input('categories');
         $activity->categories = strtolower(implode(';', collect($categories)->flatten()->toArray()));
         $activity->center_activity = $request->input('center_activity');
         $activity->save();
         if ($activity->media_id) {
             $activityMedia = ActivityMedia::firstOrCreate(['media_id' => $activity->media_id, 'activity_id' => $activity->id]);
         }
     });
     return $activity;
 }