Example #1
0
 /**
  * @param $id
  * @param $attributes
  *
  * @return bool|mixed
  *
  * @throws \Fully\Exceptions\Validation\ValidationException
  */
 public function update($id, $attributes)
 {
     $this->project = $this->find($id);
     if ($this->isValid($attributes)) {
         $file = null;
         if (isset($attributes['image'])) {
             $file = $attributes['image'];
         }
         //-------------------------------------------------------
         if ($file) {
             // delete old image
             $destinationPath = public_path() . $this->imgDir;
             File::delete($destinationPath . $this->project->file_name);
             $destinationPath = public_path() . $this->imgDir;
             $fileName = $file->getClientOriginalName();
             $fileSize = $file->getClientSize();
             $upload_success = $file->move($destinationPath, $fileName);
             if ($upload_success) {
                 // resizing an uploaded file
                 Image::make($destinationPath . $fileName)->resize($this->width, $this->height)->save($destinationPath . $fileName);
                 // thumb
                 Image::make($destinationPath . $fileName)->resize($this->thumbWidth, $this->thumbHeight)->save($destinationPath . 'thumb_' . $fileName);
                 $this->project->file_name = $fileName;
                 $this->project->file_size = $fileSize;
                 $this->project->path = $this->imgDir;
             }
         }
         //-------------------------------------------------------
         $this->project->resluggify();
         $this->project->fill($attributes)->save();
         return true;
     }
     throw new ValidationException('Project validation failed', $this->getErrors());
 }