Added improved image storage to TourController
This commit is contained in:
parent
b3179c957c
commit
4cca224587
9 changed files with 80 additions and 7 deletions
|
|
@ -19,7 +19,7 @@ class ImageController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug("User $user->name is not authorized to access image $imageName in category $category");
|
Log::debug("Unauthorized image access");
|
||||||
return response()->file(public_path()."/img/placeholder/icon_unknown.png");
|
return response()->file(public_path()."/img/placeholder/icon_unknown.png");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
use Intervention\Image\Facades\Image;
|
use Intervention\Image\Facades\Image;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class TourController extends Controller
|
class TourController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -77,6 +78,7 @@
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Log::info("TourController.store");
|
||||||
$request->validate(
|
$request->validate(
|
||||||
[
|
[
|
||||||
'name' => 'required|min:3',
|
'name' => 'required|min:3',
|
||||||
|
|
@ -88,6 +90,12 @@
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Log::info("Storage Test");
|
||||||
|
Log::info(Storage::allDirectories());
|
||||||
|
dd($request);
|
||||||
|
//error_log("Test§§§");
|
||||||
|
//Log::info($request);
|
||||||
|
|
||||||
$tour = new Tour;
|
$tour = new Tour;
|
||||||
$tour->name = $request->input('name');
|
$tour->name = $request->input('name');
|
||||||
$tour->user_id = $request->input('user_id');
|
$tour->user_id = $request->input('user_id');
|
||||||
|
|
@ -98,7 +106,7 @@
|
||||||
$tour->is_cancelled = $request->input('is_cancelled', false);
|
$tour->is_cancelled = $request->input('is_cancelled', false);
|
||||||
$tour->save();
|
$tour->save();
|
||||||
|
|
||||||
error_log("Stored deadline:" . $tour->deadline);
|
Log::info("Stored deadline:" . $tour->deadline);
|
||||||
|
|
||||||
return redirect('/tour');
|
return redirect('/tour');
|
||||||
}
|
}
|
||||||
|
|
@ -229,14 +237,14 @@
|
||||||
if (Auth::user()->role != 'ADMIN') {
|
if (Auth::user()->role != 'ADMIN') {
|
||||||
return redirect('/tour');
|
return redirect('/tour');
|
||||||
}
|
}
|
||||||
error_log("Tour:edit");
|
|
||||||
if ($tour->start < Carbon::now()) {
|
|
||||||
return view('tour.edit_old')->with('tour', $tour);
|
|
||||||
}
|
|
||||||
|
|
||||||
$tour->start = Tour::toGermanDate($tour->start);
|
$tour->start = Tour::toGermanDate($tour->start);
|
||||||
$tour->deadline = Tour::toGermanDate($tour->deadline);
|
$tour->deadline = Tour::toGermanDate($tour->deadline);
|
||||||
|
|
||||||
|
if ($tour->start < Carbon::now()) {
|
||||||
|
return view('tour.edit_old')->with('tour', $tour);
|
||||||
|
}
|
||||||
|
|
||||||
$rooms = $this->fetch_rooms($tour->id);
|
$rooms = $this->fetch_rooms($tour->id);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -255,7 +263,7 @@
|
||||||
public function update(Request $request, Tour $tour)
|
public function update(Request $request, Tour $tour)
|
||||||
{
|
{
|
||||||
|
|
||||||
error_log("Tour:update");
|
Log::info("Tour:update");
|
||||||
$tour = Tour::find($request->input('tour_id'));
|
$tour = Tour::find($request->input('tour_id'));
|
||||||
|
|
||||||
$request->validate(
|
$request->validate(
|
||||||
|
|
@ -268,6 +276,9 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
if ($request->bild) {
|
if ($request->bild) {
|
||||||
|
$this->storeImage($request->bild, "tour_".$tour->id, $request->name);
|
||||||
|
/*
|
||||||
|
Log::info("Processing image");
|
||||||
$bild = Image::make($request->bild);
|
$bild = Image::make($request->bild);
|
||||||
$breite = $bild->width();
|
$breite = $bild->width();
|
||||||
$hoehe = $bild->height();
|
$hoehe = $bild->height();
|
||||||
|
|
@ -286,6 +297,9 @@
|
||||||
->widen(96)
|
->widen(96)
|
||||||
->save(public_path() . '/img/tour/' . $tour->id . '.jpg');
|
->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');
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
$tour->name = $request->input('name');
|
$tour->name = $request->input('name');
|
||||||
|
|
@ -386,4 +400,53 @@
|
||||||
DB::delete("DELETE FROM tour_rooms WHERE tour_id = ? AND id = ?", [$tour_id, $room_id]);
|
DB::delete("DELETE FROM tour_rooms WHERE tour_id = ? AND id = ?", [$tour_id, $room_id]);
|
||||||
return redirect('tour/' . $tour_id . '/edit');
|
return redirect('tour/' . $tour_id . '/edit');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private function getImage($category, $imageName) {
|
||||||
|
Log::debug("File request for category: ".$category.", File: ".$imageName);
|
||||||
|
$user=Auth::user();
|
||||||
|
if ($user) {
|
||||||
|
|
||||||
|
if ($user->role == "ADMIN" || $user->role == "MEMBER") {
|
||||||
|
Log::info("User has proper role: ".$user->role.", serving content");
|
||||||
|
return response()->file(storage_path() . "/img_storage/".$category."/" . $imageName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::debug("User $user->name is not authorized to access image $imageName in category $category");
|
||||||
|
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";
|
||||||
|
if (!file_exists($dirPath)) {
|
||||||
|
mkdir($dirPath, 0777, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$bild = Image::make($bild);
|
||||||
|
$breite = $bild->width();
|
||||||
|
$hoehe = $bild->height();
|
||||||
|
if ($breite > $hoehe) {
|
||||||
|
Image::make($bild)
|
||||||
|
->widen(1200)
|
||||||
|
->save("$dirPath/$name"."_gross.jpg");
|
||||||
|
Image::make($bild)
|
||||||
|
->widen(64)
|
||||||
|
->save("$dirPath/$name".".jpg");
|
||||||
|
} else {
|
||||||
|
Image::make($bild)
|
||||||
|
->heighten(900)
|
||||||
|
->save("$dirPath/$name"."_gross.jpg");;
|
||||||
|
Image::make($bild)
|
||||||
|
->widen(96)
|
||||||
|
->save("$dirPath/$name".".jpg");
|
||||||
|
}
|
||||||
|
Log::info("Image saved as $dirPath/$name" . '_gross.jpg');
|
||||||
|
Log::info("Image saved as $dirPath/$name" . '.jpg');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
BIN
motorradig/public/img/tour/1.jpg
Normal file
BIN
motorradig/public/img/tour/1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
BIN
motorradig/public/img/tour/1_gross.jpg
Normal file
BIN
motorradig/public/img/tour/1_gross.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 205 KiB |
BIN
motorradig/public/img/tour/8.jpg
Normal file
BIN
motorradig/public/img/tour/8.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
BIN
motorradig/public/img/tour/8_gross.jpg
Normal file
BIN
motorradig/public/img/tour/8_gross.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 205 KiB |
|
|
@ -4,11 +4,21 @@
|
||||||
<div class="container text-center text-light mt-5">
|
<div class="container text-center text-light mt-5">
|
||||||
<h1 class="text-center">Galerie</h1>
|
<h1 class="text-center">Galerie</h1>
|
||||||
|
|
||||||
|
|
||||||
|
<h1>(Galerie Elemente)</h1>
|
||||||
<div class="container text-primary" style="display:flex">
|
<div class="container text-primary" style="display:flex">
|
||||||
<ul class="list-group offset-2 col-8">
|
<ul class="list-group offset-2 col-8">
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<h1 style="color:white;">Hochladen</h1>
|
||||||
|
|
||||||
|
<form action="/action_page.php">
|
||||||
|
<input type="file" id="myFile" name="filename" multiple>
|
||||||
|
<input type="submit">
|
||||||
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
||||||
BIN
motorradig/storage/img_storage/tour-24/test1.jpg
Normal file
BIN
motorradig/storage/img_storage/tour-24/test1.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
BIN
motorradig/storage/img_storage/tour-24/test1_gross.jpg
Normal file
BIN
motorradig/storage/img_storage/tour-24/test1_gross.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 206 KiB |
Loading…
Add table
Add a link
Reference in a new issue