Files
HeimerdingerLoL/app/Http/Controllers/SaleController.php
Rico van Zelst 85e3c4ff2e feat(controllers): optimize caching and view data passing
- Refactored the ChampionController, ChampionSkinController, HomeController, SaleController, SummonerEmoteController, and SummonerIconController to use arrow functions for cache callbacks.
- Updated the view data passing in the ChampionController, ChampionSkinController, HomeController, PostsController, SaleController, SummonerEmoteController, and SummonerIconController to use associative arrays instead of compact().
- Removed unused imports from web.php.
2024-01-06 00:15:19 +01:00

23 lines
688 B
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Cache;
class SaleController extends Controller
{
public function index()
{
$sales = Cache::remember('sales_data', 60 * 60 * 8, static function () {
$shopData = json_decode(
file_get_contents('https://api.shop.riotgames.com/v3/collections/'),
true
);
$salesData = array_filter($shopData, static fn($collection) => $collection['path'] === '/event/sales');
return reset($salesData)['dynamicCollection']['discountedProductsByProductType'] ?? [];
});
return view('sales.index', ['sales' => $sales]);
}
}