design anpasungen und url for image
This commit is contained in:
@@ -109,7 +109,8 @@ class UserNailPolishController extends Controller
|
||||
"number" => "required|string|max:50",
|
||||
"manufacturer_id" => "required_without:new_manufacturer|exists:manufacturers,id",
|
||||
"new_manufacturer" => "required_without:manufacturer_id|string|max:255|unique:manufacturers,name",
|
||||
"image" => "nullable|image|max:10240", // Max 10MB
|
||||
"image" => "nullable|image|max:10240",
|
||||
"image_url" => "nullable|url|max:500",
|
||||
], [
|
||||
"name.required" => "Der Name des Lackes ist erforderlich.",
|
||||
"number.required" => "Die Nummer des Lackes ist erforderlich.",
|
||||
@@ -118,6 +119,7 @@ class UserNailPolishController extends Controller
|
||||
"new_manufacturer.unique" => "Ein Hersteller mit diesem Namen existiert bereits.",
|
||||
"image.image" => "Die Datei muss ein Bild sein.",
|
||||
"image.max" => "Das Bild darf maximal 10MB groß sein.",
|
||||
"image_url.url" => "Bitte geben Sie eine gültige URL ein (https://...).",
|
||||
]);
|
||||
|
||||
try {
|
||||
@@ -138,19 +140,45 @@ class UserNailPolishController extends Controller
|
||||
$nailPolish->number = trim($request->number);
|
||||
$nailPolish->manufacturer_id = $manufacturerId;
|
||||
|
||||
// Vereinfachte Bildverarbeitung ohne Intervention Image
|
||||
// Bild per Datei-Upload
|
||||
if ($request->hasFile("image") && $request->file("image")->isValid()) {
|
||||
$image = $request->file("image");
|
||||
|
||||
// Erstelle einen eindeutigen Dateinamen
|
||||
$filename = "nail_polish_" . time() . "_" . uniqid() . "." . $image->getClientOriginalExtension();
|
||||
$path = "nail_polishes/" . $filename;
|
||||
|
||||
// Speichere das Bild direkt ohne Verarbeitung
|
||||
Storage::disk("public")->putFileAs("nail_polishes", $image, $filename);
|
||||
$nailPolish->image_path = $path;
|
||||
|
||||
\Log::info("Bild erfolgreich gespeichert: " . $path);
|
||||
|
||||
// Bild per URL herunterladen
|
||||
} elseif ($request->filled("image_url")) {
|
||||
$imageUrl = trim($request->image_url);
|
||||
try {
|
||||
$response = \Illuminate\Support\Facades\Http::timeout(15)
|
||||
->withHeaders(['User-Agent' => 'Mozilla/5.0'])
|
||||
->get($imageUrl);
|
||||
|
||||
if (!$response->successful()) {
|
||||
throw new \Exception("HTTP-Status " . $response->status());
|
||||
}
|
||||
|
||||
$contentType = strtolower($response->header('Content-Type') ?? '');
|
||||
if (!str_starts_with($contentType, 'image/')) {
|
||||
throw new \Exception("URL enthält kein Bild (Content-Type: {$contentType})");
|
||||
}
|
||||
|
||||
$ext = 'jpg';
|
||||
if (str_contains($contentType, 'png')) $ext = 'png';
|
||||
elseif (str_contains($contentType, 'gif')) $ext = 'gif';
|
||||
elseif (str_contains($contentType, 'webp')) $ext = 'webp';
|
||||
|
||||
$filename = "nail_polish_" . time() . "_" . uniqid() . "." . $ext;
|
||||
$path = "nail_polishes/" . $filename;
|
||||
Storage::disk("public")->put($path, $response->body());
|
||||
$nailPolish->image_path = $path;
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Log::warning("Bild-URL konnte nicht geladen werden: " . $e->getMessage());
|
||||
// Lack wird ohne Bild gespeichert, kein Abbruch
|
||||
}
|
||||
}
|
||||
|
||||
$nailPolish->save();
|
||||
|
||||
Reference in New Issue
Block a user