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 @@
Eintrag anpassen
+ @if($item->latestPhotoLog) + + @endif +