Ejemplo n.º 1
0
 /**
  * Handle user photo uploads
  *
  * @param Request $request
  * @param ImageHandlerInterface $imageHandler
  * @return \Illuminate\Http\RedirectResponse
  */
 public function upload(Request $request, ImageHandlerInterface $imageHandler)
 {
     $user = Auth::user();
     $croppedPhotoData = $request->input('photoDataURI');
     $upload = $imageHandler->uploadUserPhoto($user, $croppedPhotoData);
     // @todo Add validation to prevent any kind of injection
     $request->session()->flash($upload['flash'], $upload['message']);
     if ($request->has('redirectTo')) {
         return Response::redirectTo($request->input('redirectTo'));
     }
     return Response::redirectTo('/');
 }
Ejemplo n.º 2
0
 /**
  * Execute the console command.
  *
  * @param ImageHandlerInterface $imageHandler
  * @param CacheHandlerInterface $cacheHandler
  * @param SearchHandlerInterface $searchHandler
  * @return mixed
  */
 public function handle(ImageHandlerInterface $imageHandler, CacheHandlerInterface $cacheHandler, SearchHandlerInterface $searchHandler)
 {
     // Find all links with photos URLs that need thumbnails
     $links = Link::with('item', 'item.user')->whereNull('photo')->take(100)->get();
     /* @var $link \App\Models\Link */
     foreach ($links as $link) {
         // Try to generate a thumbnail for the desired photo
         try {
             $generatedFilename = $imageHandler->generateThumbnail($link->photo_url);
             if ($generatedFilename) {
                 $link->photo = $generatedFilename;
                 $link->save();
                 // Update Search
                 $searchHandler->update($link);
                 // Update cache for user
                 $cacheHandler->del(CacheHandlerInterface::MAINPAGE, $link->item->user->id);
             }
         } catch (\Exception $e) {
             error_log($e);
         }
     }
 }