public function setImageAttribute($value) { if ($this->image) { $this->image->delete(); } if (!is_null($value)) { $imageName = last(explode('/', $value)); $targetDirectory = config('admin.imagesUploadDirectory') . '/slides'; $toDirectory = public_path($targetDirectory); if (!\File::exists($toDirectory)) { \File::makeDirectory($toDirectory); } if (\File::exists($value)) { \File::move(public_path($value), $toDirectory . '/' . $imageName); } $this->attributes['image'] = $targetDirectory . '/' . $imageName; } }
/** * Save content main picture * * @param null|File $file */ public function savePicture($file, $maxWidth = 1024) { if ($file) { $filename = 'picture.' . $file->getClientOriginalExtension(); $file->move(public_path($this->getStoragePath()), $filename); $this->seo_image = $filename; $this->save(); // Go resize if not empty if (!empty($maxWidth)) { $this->resizeImage(public_path($this->getStoragePath() . '/' . $filename), $maxWidth); } } }