/** * @param Product $model * * @return bool */ public function saving(Product $model) { // if there is a new image, then do sth. otherwise leave the original one if ($model->isDirty('image')) { // check if old product images exist on the filesystem and delete them $deleteResult = $this->deleteProductImages($model); $path = $this->image->init($model, 'image')->getImage(); if (empty($path)) { return false; } $model->image_large = $path; // create the small image $model->image = $this->image->reduceImage($model->image_large, config('site.products.images.reduce_ratio')); if (is_null($model->image_large or is_null($model->image))) { // error. just bail out return false; } return true; } return true; }