/** * @param UploadedFile $file */ public function saveImage(UploadedFile $file) { $this->deleteImage(); $image = Image::make($file); $image_name = Advert::generateImageName(); $advert_category = $this->advert_category; $width = $advert_category->width ? $advert_category->width : null; $height = $advert_category->height ? $advert_category->height : null; if ($advert_category->width === null || $advert_category->height === null) { $image->resize($advert_category->width, $advert_category->height, function ($constraint) { $constraint->aspectRatio(); }); } else { $image->resize($advert_category->width, $advert_category->height); } $image->save(config('laravel-advert.upload_path') . '/' . $image_name); $this->update(['image_url' => config('laravel-advert.upload_path') . '/' . $image_name, 'image_path' => config('laravel-advert.upload_path') . '/' . $image_name]); }
/** * Simple controller method to add clicks count * * * @param $advert_id * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function index($advert_id) { $advert = Advert::findOrFail($advert_id); $advert->plusClicks(); return redirect($advert->url); }