diff --git a/app/Http/Controllers/ShoppingListController.php b/app/Http/Controllers/ShoppingListController.php index b418dd1..afdfdf5 100644 --- a/app/Http/Controllers/ShoppingListController.php +++ b/app/Http/Controllers/ShoppingListController.php @@ -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(); diff --git a/app/Models/ShoppingItem.php b/app/Models/ShoppingItem.php index a91ce91..5898cb0 100644 --- a/app/Models/ShoppingItem.php +++ b/app/Models/ShoppingItem.php @@ -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', '!=', ''); + }); + } } diff --git a/resources/views/shopping-list/index.blade.php b/resources/views/shopping-list/index.blade.php index 2d0ccd5..997afb0 100644 --- a/resources/views/shopping-list/index.blade.php +++ b/resources/views/shopping-list/index.blade.php @@ -139,18 +139,18 @@
Letzter Preis: {{ $item->latestPriceLog?->price_decimal !== null ? number_format((float) $item->latestPriceLog->price_decimal, 2, ',', '.') . ' EUR' : '-' }}
- @if($item->latestPriceLog?->photo_path) + @if($item->latestPhotoLog)

Kassenbon / Foto

- + Kassenbon - Foto oeffnen (bei HEIC oft noetig) + Foto oeffnen (bei HEIC oft noetig)
@endif diff --git a/resources/views/shopping-list/partials/item-pencil-panel.blade.php b/resources/views/shopping-list/partials/item-pencil-panel.blade.php index 4a9cfa5..87118a4 100644 --- a/resources/views/shopping-list/partials/item-pencil-panel.blade.php +++ b/resources/views/shopping-list/partials/item-pencil-panel.blade.php @@ -15,6 +15,21 @@

Eintrag anpassen

+ @if($item->latestPhotoLog) +
+

Gespeichertes Foto

+ + Kassenbon + + Foto gross oeffnen +
+ @endif +
@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') }})
- @if($item->latestPriceLog->photo_path) -
-

Letztes Foto

- - Kassenbon - - Foto in neuem Tab oeffnen -
- @endif @endif