hasMany('App\Floor'); } public function scopeFeatured($query) { return $query->whereFeatured(1); } public function setImageAttribute($value) { $destinationPath = 'uploads/'; if($value){ if($this->image){ File::delete($this->image); File::delete($this->thumbnail); } $valueName = pathinfo($value->getClientOriginalName(), PATHINFO_FILENAME); $extension = pathinfo($value->getClientOriginalName(), PATHINFO_EXTENSION); $newFileName = md5($valueName.time()).'.'.$extension; $img = Image::make($value->getRealPath()); $img->resize(1920, 1920, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }); $img->save($destinationPath.'images/'.$newFileName); $img->fit(600, 400); $img->save($destinationPath.'thumbnails/'.$newFileName); $this->attributes['image'] = $destinationPath.'images/'.$newFileName; $this->attributes['thumbnail'] = $destinationPath.'thumbnails/'.$newFileName; } } }