61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
<?php
|
|
// Robuste Bild-URL-Lösung für NeoNail DB
|
|
// Fügen Sie diese Helper-Funktion hinzu
|
|
|
|
// In app/Helpers/ImageHelper.php erstellen:
|
|
namespace App\Helpers;
|
|
|
|
class ImageHelper
|
|
{
|
|
public static function getImageUrl($imagePath)
|
|
{
|
|
if (!$imagePath) {
|
|
return null;
|
|
}
|
|
|
|
// Prüfe ob das Bild existiert
|
|
if (!\Storage::disk('public')->exists($imagePath)) {
|
|
return null;
|
|
}
|
|
|
|
// Erstelle die URL
|
|
$url = \Storage::disk('public')->url($imagePath);
|
|
|
|
// Stelle sicher, dass HTTPS verwendet wird
|
|
if (strpos($url, 'http://') === 0) {
|
|
$url = str_replace('http://', 'https://', $url);
|
|
}
|
|
|
|
return $url;
|
|
}
|
|
|
|
public static function getImageUrlOrPlaceholder($imagePath, $size = '400x400')
|
|
{
|
|
$url = self::getImageUrl($imagePath);
|
|
|
|
if ($url) {
|
|
return $url;
|
|
}
|
|
|
|
// Fallback zu einem Placeholder-Bild
|
|
return "https://via.placeholder.com/{$size}/cccccc/666666?text=Kein+Bild";
|
|
}
|
|
}
|
|
|
|
// In der View verwenden:
|
|
// {{ \App\Helpers\ImageHelper::getImageUrlOrPlaceholder($nailPolish->image_path) }}
|
|
|
|
// Oder als Blade-Directive in AppServiceProvider.php registrieren:
|
|
/*
|
|
public function boot()
|
|
{
|
|
Blade::directive('nailPolishImage', function ($expression) {
|
|
return "<?php echo \App\Helpers\ImageHelper::getImageUrlOrPlaceholder($expression); ?>";
|
|
});
|
|
}
|
|
*/
|
|
|
|
// Dann in der View:
|
|
// @nailPolishImage($nailPolish->image_path)
|
|
?>
|