This commit is contained in:
Stefan Zwischenbrugger 2026-03-29 21:57:49 +02:00
parent 122f6920dd
commit e9b5837791
4 changed files with 32 additions and 19 deletions

View File

@ -33,7 +33,7 @@ class ShoppingListController extends Controller
$items = ShoppingItem::query()
->where('shopping_list_id', $currentList->id)
->with(['store', 'latestPriceLog.store', 'creator'])
->with(['store', 'latestPriceLog.store', 'latestPhotoLog', 'creator'])
->latest()
->get();

View File

@ -51,4 +51,16 @@ class ShoppingItem extends Model
{
return $this->hasOne(ItemPriceLog::class)->latestOfMany('logged_at');
}
/**
* Neuester Preis-Eintrag, der ein gespeichertes Foto hat (kann aelter sein als latestPriceLog).
*/
public function latestPhotoLog(): HasOne
{
return $this->hasOne(ItemPriceLog::class)->ofMany([
'logged_at' => 'max',
], function ($query) {
$query->whereNotNull('photo_path')->where('photo_path', '!=', '');
});
}
}

View File

@ -139,18 +139,18 @@
<div class="text-sm text-gray-600">
Letzter Preis: {{ $item->latestPriceLog?->price_decimal !== null ? number_format((float) $item->latestPriceLog->price_decimal, 2, ',', '.') . ' EUR' : '-' }}
</div>
@if($item->latestPriceLog?->photo_path)
@if($item->latestPhotoLog)
<div class="mt-2">
<p class="text-xs text-gray-500 mb-1">Kassenbon / Foto</p>
<a href="{{ $item->latestPriceLog->photoUrl() }}" target="_blank" rel="noopener noreferrer" class="block">
<a href="{{ $item->latestPhotoLog->photoUrl() }}" target="_blank" rel="noopener noreferrer" class="block">
<img
src="{{ $item->latestPriceLog->photoUrl() }}"
src="{{ $item->latestPhotoLog->photoUrl() }}"
alt="Kassenbon"
class="max-h-48 w-full max-w-xs rounded-lg border border-gray-200 object-contain bg-gray-50"
loading="lazy"
>
</a>
<a href="{{ $item->latestPriceLog->photoUrl() }}" target="_blank" rel="noopener noreferrer" class="text-xs text-blue-600 hover:underline mt-1 inline-block">Foto oeffnen (bei HEIC oft noetig)</a>
<a href="{{ $item->latestPhotoLog->photoUrl() }}" target="_blank" rel="noopener noreferrer" class="text-xs text-blue-600 hover:underline mt-1 inline-block">Foto oeffnen (bei HEIC oft noetig)</a>
</div>
@endif
</div>

View File

@ -15,6 +15,21 @@
<div class="absolute right-0 z-20 mt-2 w-[min(calc(100vw-2rem),22rem)] rounded-xl border border-gray-200 bg-white p-4 shadow-lg sm:w-80">
<p class="mb-3 text-sm font-medium text-gray-900">Eintrag anpassen</p>
@if($item->latestPhotoLog)
<div class="mb-4 rounded-lg border border-emerald-200 bg-emerald-50/80 p-3">
<p class="text-xs font-medium text-emerald-900 mb-2">Gespeichertes Foto</p>
<a href="{{ $item->latestPhotoLog->photoUrl() }}" target="_blank" rel="noopener noreferrer" class="block">
<img
src="{{ $item->latestPhotoLog->photoUrl() }}"
alt="Kassenbon"
class="max-h-40 w-full rounded border border-emerald-200/80 object-contain bg-white"
loading="lazy"
>
</a>
<a href="{{ $item->latestPhotoLog->photoUrl() }}" target="_blank" rel="noopener noreferrer" class="text-xs text-emerald-800 hover:underline mt-2 inline-block">Foto gross oeffnen</a>
</div>
@endif
<form method="POST" action="{{ route('shopping-items.update', $item) }}" class="grid grid-cols-1 gap-2">
@csrf
@method('PATCH')
@ -124,20 +139,6 @@
bei {{ $item->latestPriceLog->store?->name ?: 'ohne Geschaeft' }}
({{ optional($item->latestPriceLog->logged_at)->format('d.m.Y H:i') }})
</div>
@if($item->latestPriceLog->photo_path)
<div class="mt-2">
<p class="text-xs text-gray-600 mb-1">Letztes Foto</p>
<a href="{{ $item->latestPriceLog->photoUrl() }}" target="_blank" rel="noopener noreferrer" class="block">
<img
src="{{ $item->latestPriceLog->photoUrl() }}"
alt="Kassenbon"
class="max-h-36 w-full rounded border border-gray-200 object-contain bg-gray-50"
loading="lazy"
>
</a>
<a href="{{ $item->latestPriceLog->photoUrl() }}" target="_blank" rel="noopener noreferrer" class="text-xs text-blue-600 hover:underline mt-1 inline-block">Foto in neuem Tab oeffnen</a>
</div>
@endif
@endif
<button
type="submit"