Use MicroKernelTrait to bootstrap application. Rewrote routes, controllers and structure of application a bit. Including use of twig.
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user