Files
ryobi-crawler/src/Controller/ProductController.php

19 lines
685 B
PHP

<?php
namespace Krzysiej\RyobiCrawler\Controller;
use Krzysiej\RyobiCrawler\Models\Product;
final class ProductController extends BaseController
{
public function __invoke(int $productId): void
{
$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]);
}
}