Files
HeimerdingerLoL/app/Http/Controllers/ChampionController.php
Rico van Zelst e6dcfacb31 feat: Add streamers to champion show view
- Added loading of streamers data in the champion show view.
- Updated ChampionController to load streamers for display.
2024-03-23 02:48:08 +01:00

52 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\StoreChampionRequest;
use App\Http\Requests\UpdateChampionRequest;
use App\Models\Champion;
use App\Models\ChampionRoles;
use Illuminate\Support\Facades\Cache;
class ChampionController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$eightHoursInSeconds = 60 * 60 * 8;
$champions = Cache::remember('championsListAllCache', $eightHoursInSeconds, static fn () => Champion::orderBy('name')->get());
$roles = Cache::remember('championsRolesCache', $eightHoursInSeconds, static fn () => ChampionRoles::orderBy('champion_name')->get());
return view('champions.index', ['champions' => $champions, 'roles' => $roles]);
}
/**
* Display the specified resource.
*/
public function show(Champion $champion)
{
$threeDaysInSeconds = 60 * 60 * 24 * 3;
$sixMonthsInSeconds = 60 * 60 * 24 * 30 * 6;
$tenMinutesInSeconds = 60 * 10;
$champion = Cache::remember('championShowCache' . $champion->slug, $threeDaysInSeconds, static fn () => $champion->load('streamers', 'skins', 'lanes'));
//$streamers = Cache::remember('championStreamersCache' . $champion->slug, $tenMinutesInSeconds, static fn () => $champion->streamers);
$streamers = $champion->load('streamers')->streamers;
$splashColor = Cache::remember(
'championSplashColorCache' . $champion->slug,
$sixMonthsInSeconds,
static fn () => getAverageColorFromImageUrl($champion->getChampionImageAttribute())
);
$champion->splash_color = $splashColor;
return view('champions.show', ['champion' => $champion, 'streamers' => $streamers]);
}
}