Beispiel #1
0
 public function savePhotos($params = [])
 {
     $remove_photos = (array) $params['remove_photos'];
     $photos = $params['photos'];
     $main_photo = (int) $params['main_photo'];
     $path = $this->photos_path . '/' . $this->id;
     $id = $this->id;
     $food_photos = (array) $this->photos;
     foreach ($remove_photos as $photo) {
         \Storage::delete($path . '/' . $food_photos[$photo]);
         unset($food_photos[$photo]);
     }
     if ($photos) {
         foreach ($photos as $key => $photo) {
             $file_name = md5(str_random(30)) . '.jpg';
             \Storage::put($path . '/' . $file_name, file_get_contents($photo->getRealPath()));
             $food_photos[] = $file_name;
         }
     }
     $food_photos = array_values($food_photos);
     if ($food_photos) {
         if ($main_photo) {
             $this->main_photo = $food_photos[$main_photo];
         }
         if (!$this->main_photo || array_search($this->main_photo, $food_photos) === FALSE) {
             $this->main_photo = $food_photos[0];
         }
     } else {
         $this->main_photo = '';
     }
     $this->photos = $food_photos;
     $this->save();
 }
Beispiel #2
0
 public function savePhoto($photo)
 {
     if ($photo) {
         \Storage::put('photos/categories/' . $this->id . '.jpg', file_get_contents($photo->getRealPath()));
         $this->photo = TRUE;
         $this->save();
     }
 }
Beispiel #3
0
 public function saveImage($announcement)
 {
     $ext = Input::file('image')->getClientOriginalExtension();
     Storage::put('images/' . $announcement->id . '/' . $announcement->id . '.' . $ext, file_get_contents($request->file('image')->getRealPath()));
     /* $file = array('image' => Input::file('image'));
        // setting up rules
        $rules = array('image' => 'required',); //mimes:jpeg,bmp,png and for max size max:10000
        // doing the validation, passing post data, rules and the messages
        $validator = Validator::make($file, $rules);
        if ($validator->fails()) {
            // send back to the page with the input data and errors
            return Redirect::to('upload')->withInput()->withErrors($validator);
        }
        else {
            // checking file is valid.
            if (Input::file('image')->isValid()) {
                $destinationPath = 'uploads/'.$announcement->id; // upload path
                $extension = Input::file('image')->getClientOriginalExtension(); // getting image extension
                $fileName = $announcement->id.'.'.$extension; // renameing image
                Input::file('image')->move($destinationPath, $fileName); // uploading file to given path
                // sending back with message
                Session::flash('success', 'Upload successfully');
            }
            else {
                // sending back with error message.
                Session::flash('error', 'uploaded file is not valid');
            }
        }*/
 }