コード例 #1
1
ファイル: Advert.php プロジェクト: adumskis/laravel-advert
 /**
  * @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]);
 }
コード例 #2
0
 /**
  * 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);
 }