/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postStore(Request $request)
 {
     if (Photo::create($request->all())) {
         return $this->getIndex();
     } else {
         return $this->errorCreated();
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store()
 {
     $photo = Photo::create($this->request->all());
     $image = $this->request->file('image');
     //$originalName = $image->getClientOriginalName();
     $originalExtension = $image->getClientOriginalExtension();
     $name = 'PH' . date('YmdHis') . '.' . $originalExtension;
     \Storage::disk('local')->put($name, \File::get($image));
     $photo->file_name = $name;
     $photo->save();
     return redirect()->route('feed');
 }
 public function postUpload(Request $request)
 {
     /** @var Ulibier $user */
     $user = JWTAuth::parseToken()->authenticate();
     $image = $request->file('image');
     $photo_uptime = time();
     $hash = uniqid($photo_uptime, true);
     $imageFilename = $hash . '.' . $image->getClientOriginalExtension();
     Storage::put('/imgtemp/' . $imageFilename, file_get_contents($image), 'public');
     $photo = Photo::create();
     $photo->photo_uptime = $photo_uptime;
     $photo->photo_hash = $hash;
     $photo->photo_extensions = $image->getClientOriginalExtension();
     $photo->des_id = $request->input('des_id');
     $photo->save();
     $user->photos()->save($photo);
     return $photo;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param Destination $dest
  * @param  \Illuminate\Http\Request $request
  * @return \Illuminate\Http\Response
  */
 public function store(Destination $dest, Request $request)
 {
     $photo_url = $request->input('photo_url');
     $photo_like = $request->input('photo_like', 0);
     $photo_csvFile = database_path('seeds/csv/Photo.csv');
     $csv = new CSV();
     $photo_csvContent = $csv->fromFile($photo_csvFile)->toArray();
     $photo_added = array(['username' => \Auth::user()->username, 'des_id' => $dest->des_id, 'photo_like' => $photo_like, 'photo_sample_name' => $photo_url]);
     array_push($photo_csvContent, $photo_added);
     $csv->with($photo_csvContent)->put($photo_csvFile);
     // insert image to database
     $uploadtime = time();
     $img_ext = pathinfo($photo_url, PATHINFO_EXTENSION) || 'jpg';
     $hash = uniqid($uploadtime, true);
     $local_imgname = $hash . '.' . $img_ext;
     Storage::put('/imgtemp/' . $local_imgname, file_get_contents($photo_url));
     /** @var Photo $photo */
     $photo = Photo::create(array('username' => \Auth::user()->username, 'des_id' => $dest->des_id, 'photo_like' => $photo_like, 'photo_hash' => $hash, 'photo_uptime' => $uploadtime, 'photo_extensions' => $img_ext));
     return response()->json($photo, 200);
 }
 public static function addPhoto($data, $relationshipId = null, $categoryName = null, $displayName = null)
 {
     $pixelFormats = [350, 300, 200, 125, 75, 25];
     if (!is_null($data)) {
         $time = Carbon\Carbon::now()->timestamp;
         $media = \Image::make($data);
         $extension = $data->getClientOriginalExtension();
         $mediaName = $time . rand(5, 200000);
         $fileName = $mediaName . "." . $extension;
         $media->save(public_path() . '/uploads/photos/' . $fileName, 60);
         foreach ($pixelFormats as $format) {
             $media->resize($format, null, function ($constraint) {
                 $constraint->aspectRatio();
             });
             $media->save(public_path() . '/uploads/photos/' . $format . 'px_' . $fileName, 60);
         }
         if (is_null($displayName)) {
             $displayName = $mediaName;
         }
         if (is_null($relationshipId)) {
             $relationshipId = 0;
         }
         $mediaCreate = Photo::create(['displayName' => $displayName, 'fileName' => $fileName, 'categoryName' => $categoryName, 'relId' => $relationshipId]);
         return $mediaCreate;
     }
 }
 public function photo()
 {
     $input = Input::all();
     if (array_key_exists('file_data', $input)) {
         $id = $input['terrain_id'];
         $file = $input['file_data'];
         $path = 'photos/terrains/' . $id;
         $res = $file->move(public_path($path), $file->getClientOriginalName());
         $data = [];
         $data['terrain_id'] = $id;
         $data['author'] = access()->user()->id;
         $data['path'] = $res->getPathName();
         $data['extention'] = $res->getExtension();
         $data['storage'] = $res->getSize();
         $data['location'] = asset($path . '/' . $res->getFileName());
         $photo = Photo::create($data);
         return success(['photo' => $photo]);
     }
     return success();
 }