diff --git a/motorradig/app/Http/Controllers/TourController.php b/motorradig/app/Http/Controllers/TourController.php index 077762c..38357b9 100644 --- a/motorradig/app/Http/Controllers/TourController.php +++ b/motorradig/app/Http/Controllers/TourController.php @@ -12,7 +12,6 @@ use Intervention\Image\Facades\Image; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; - use Illuminate\Support\Str; class TourController extends Controller { @@ -114,6 +113,10 @@ $tour->is_cancelled = $request->input('is_cancelled', false); $tour->save(); + if ($request->hasFile('bild')) { + $this->storeTourImage($request->bild, $tour->id); + } + Log::info("Stored deadline:" . $tour->deadline); return redirect('/tour'); @@ -295,31 +298,8 @@ ] ); - if ($request->bild) { - $this->storeImage($request->bild, "tour_".$tour->id, $request->name); - /* - Log::info("Processing image"); - $bild = Image::make($request->bild); - $breite = $bild->width(); - $hoehe = $bild->height(); - if ($breite > $hoehe) { - Image::make($request->bild) - ->widen(1200) - ->save(public_path() . '/img/tour/' . $tour->id . '_gross.jpg'); - Image::make($request->bild) - ->widen(64) - ->save(public_path() . '/img/tour/' . $tour->id . '.jpg'); - } else { - Image::make($request->bild) - ->heighten(900) - ->save(public_path() . '/img/tour/' . $tour->id . '_gross.jpg'); - Image::make($request->bild) - ->widen(96) - ->save(public_path() . '/img/tour/' . $tour->id . '.jpg'); - } - Log::info("Image saved as ". public_path() . '/img/tour/' . $tour->id . '_gross.jpg'); - Log::info("Image saved as ". public_path() . '/img/tour/' . $tour->id . '.jpg'); - */ + if ($request->hasFile('bild')) { + $this->storeTourImage($request->bild, $tour->id); } @@ -447,35 +427,34 @@ return response()->file(public_path()."/img/placeholder/icon_unknown.png"); } - private function storeImage($bild, $category, $name) { - $cat=Str::slug($category); - $name=Str::slug($name); - - $dirPath = storage_path() . "/img_storage/$cat"; + private function storeTourImage($bild, $tourId) { + // The tour thumbnail is displayed from public/img/tour, so it has to be + // stored there (and not in the gallery directory under storage/). + $dirPath = public_path('img/tour'); if (!file_exists($dirPath)) { mkdir($dirPath, 0777, true); } - $bild = Image::make($bild); - $breite = $bild->width(); - $hoehe = $bild->height(); + $image = Image::make($bild); + $breite = $image->width(); + $hoehe = $image->height(); if ($breite > $hoehe) { Image::make($bild) ->widen(1200) - ->save("$dirPath/$name"."_gross.jpg"); + ->save("$dirPath/{$tourId}_gross.jpg"); Image::make($bild) ->widen(64) - ->save("$dirPath/$name".".jpg"); + ->save("$dirPath/{$tourId}.jpg"); } else { Image::make($bild) ->heighten(900) - ->save("$dirPath/$name"."_gross.jpg");; + ->save("$dirPath/{$tourId}_gross.jpg"); Image::make($bild) ->widen(96) - ->save("$dirPath/$name".".jpg"); + ->save("$dirPath/{$tourId}.jpg"); } - Log::info("Image saved as $dirPath/$name" . '_gross.jpg'); - Log::info("Image saved as $dirPath/$name" . '.jpg'); + Log::info("Image saved as $dirPath/{$tourId}_gross.jpg"); + Log::info("Image saved as $dirPath/{$tourId}.jpg"); } } diff --git a/motorradig/resources/views/tour/create.blade.php b/motorradig/resources/views/tour/create.blade.php index 9146186..e18a828 100644 --- a/motorradig/resources/views/tour/create.blade.php +++ b/motorradig/resources/views/tour/create.blade.php @@ -43,8 +43,8 @@ @if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg'))) - - + + @else diff --git a/motorradig/resources/views/tour/edit.blade.php b/motorradig/resources/views/tour/edit.blade.php index 9b7fd69..960a4a8 100644 --- a/motorradig/resources/views/tour/edit.blade.php +++ b/motorradig/resources/views/tour/edit.blade.php @@ -59,9 +59,10 @@ @if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg'))) - - + @else diff --git a/motorradig/resources/views/tour/edit_old.blade.php b/motorradig/resources/views/tour/edit_old.blade.php index 584d12a..93daf0a 100644 --- a/motorradig/resources/views/tour/edit_old.blade.php +++ b/motorradig/resources/views/tour/edit_old.blade.php @@ -36,8 +36,8 @@ @if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg'))) - - + + @else diff --git a/motorradig/resources/views/tour/show.blade.php b/motorradig/resources/views/tour/show.blade.php index de2211e..e097d1f 100644 --- a/motorradig/resources/views/tour/show.blade.php +++ b/motorradig/resources/views/tour/show.blade.php @@ -58,9 +58,10 @@ @if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg'))) - - + @else diff --git a/motorradig/resources/views/tour/show_old.blade.php b/motorradig/resources/views/tour/show_old.blade.php index b05b6db..5a1a03f 100644 --- a/motorradig/resources/views/tour/show_old.blade.php +++ b/motorradig/resources/views/tour/show_old.blade.php @@ -44,8 +44,8 @@ @if(file_exists (public_path ('img/tour/'.$tour->id.'.jpg'))) - - + + @else