Add twig extra bundle to use currency formatter filter. Add custom twig method to display number of active promos. Remove old index.php file.
This commit is contained in:
23
src/Twig/AppExtension.php
Normal file
23
src/Twig/AppExtension.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Krzysiej\RyobiCrawler\Twig;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Krzysiej\RyobiCrawler\Models\Product;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class AppExtension extends AbstractExtension
|
||||
{
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction('promosCount', [$this, 'promosCount']),
|
||||
];
|
||||
}
|
||||
|
||||
public function promosCount(): int
|
||||
{
|
||||
return Product::whereHas('currentPrice', fn(Builder $query) => $query->whereColumn('price', '<', 'productStandardPrice'))->with(['currentPrice'])->count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user