Use MicroKernelTrait to bootstrap application. Rewrote routes, controllers and structure of application a bit. Including use of twig.

This commit is contained in:
Krzysztof Płaczek
2024-10-19 16:01:54 +02:00
parent 3d47726a81
commit 5ee1bba812
16 changed files with 1593 additions and 73 deletions

View File

@@ -4,6 +4,8 @@ namespace Krzysiej\RyobiCrawler\Controller;
use Illuminate\Support\ItemNotFoundException;
use Krzysiej\RyobiCrawler\Models\Product;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
@@ -15,7 +17,8 @@ final class ProductController extends BaseController
* @throws RuntimeError
* @throws LoaderError
*/
public function __invoke(int $productId): void
#[Route('/product/{productId<\d+>}', name: 'app_product')]
public function __invoke(int $productId): Response
{
$product = Product::with([
'price' => fn($query) => $query->orderBy('created_at', 'desc')
@@ -27,6 +30,6 @@ final class ProductController extends BaseController
$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]);
return $this->render('product.html.twig', ['product' => $product, 'price_list' => $priceList, 'price_dates' => $priceDates]);
}
}