public function setImageAttribute($file)
{
// Only if a file is selected
if ($file) {
if (Input::hasFile('image')) {
// If an actual file is selected
File::exists(public_path() . '/uploads/') || File::makeDirectory(public_path() . '/uploads/');
File::exists(public_path() . '/' . $this->images_path) || File::makeDirectory(public_path() . '/' . $this->images_path);
$file_name = $file->getClientOriginalName();
$image = Image::make($file->getRealPath());
if (isset($this->attributes['image'])) {
// Delete old image
$old_image = $this->getIconAttribute();
File::exists($old_image) && File::delete($old_image);
}
$image->save($this->images_path . $file_name);
$file_name = $this->images_path . $file_name;
} else {
$file_name = $file;
}
$this->attributes['image'] = $file_name;
}
}