Autostart docker app unless stopped on purpose. Update README.md and describe cron scheduling. Add chart to product view and sort product prices.

This commit is contained in:
Krzysztof Płaczek
2024-10-15 20:20:57 +02:00
parent d043e8efb1
commit 3cc5d73758
5 changed files with 67 additions and 7 deletions

View File

@@ -8,7 +8,11 @@ final class ProductController extends BaseController
{
public function __invoke(int $productId): void
{
$product = Product::with('price')->find($productId);
$this->twig->display('product.html.twig', ['product' => $product ?? []]);
$product = Product::with([
'price' => fn($query) => $query->orderBy('created_at', 'desc')
])->find($productId);
$priceList = $product->price()->pluck('price')->implode(',');
$priceDates = $product->price()->pluck('created_at')->map(fn($date) => $date->format('Y-m-d'))->implode("','");
$this->twig->display('product.html.twig', ['product' => $product ?? [], 'price_list' => $priceList, 'price_dates' => $priceDates]);
}
}