mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 10:10:48 +01:00
feat: Add streamers to champion show view
- Added loading of streamers data in the champion show view. - Updated ChampionController to load streamers for display.
This commit is contained in:
@@ -24,22 +24,6 @@ class ChampionController extends Controller
|
||||
return view('champions.index', ['champions' => $champions, 'roles' => $roles]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(StoreChampionRequest $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
@@ -47,41 +31,21 @@ class ChampionController extends Controller
|
||||
{
|
||||
$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('skins', 'lanes'));
|
||||
$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,
|
||||
'championSplashColorCache' . $champion->slug,
|
||||
$sixMonthsInSeconds,
|
||||
static fn () => getAverageColorFromImageUrl($champion->getChampionImageAttribute())
|
||||
);
|
||||
|
||||
$champion->splash_color = $splashColor;
|
||||
|
||||
return view('champions.show', ['champion' => $champion]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit(Champion $champion)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(UpdateChampionRequest $request, Champion $champion)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(Champion $champion)
|
||||
{
|
||||
//
|
||||
return view('champions.show', ['champion' => $champion, 'streamers' => $streamers]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class StreamerPanelController extends Controller
|
||||
public function index()
|
||||
{
|
||||
return view('streamerpanel.index', [
|
||||
'streamers' => Streamer::all(),
|
||||
'streamers' => Streamer::with('champion')->get(),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -33,8 +33,7 @@ class StreamerPanelController extends Controller
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'champion_id' => 'required|exists:champions,id',
|
||||
$request->validate(['champion_id' => 'required|exists:champions,champion_id',
|
||||
'platform' => 'required|in:twitch,youtube,kick,douyu,huya',
|
||||
'username' => 'required|string',
|
||||
'displayname' => 'required|string',
|
||||
|
||||
@@ -94,6 +94,11 @@ class Champion extends Model
|
||||
return $this->hasOne(ChampionRoles::class, 'champion_id', 'champion_id');
|
||||
}
|
||||
|
||||
public function streamers()
|
||||
{
|
||||
return $this->hasMany(Streamer::class, 'champion_id', 'champion_id');
|
||||
}
|
||||
|
||||
public function getChampionImageAttribute($centered = true): string
|
||||
{
|
||||
$url = 'https://cdn.communitydragon.org/latest/champion/'.$this->champion_id.'/splash-art';
|
||||
|
||||
@@ -4,6 +4,8 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use App\Models\Champion;
|
||||
|
||||
class Streamer extends Model
|
||||
{
|
||||
@@ -11,10 +13,6 @@ class Streamer extends Model
|
||||
|
||||
protected $fillable = ['champion_id', 'platform', 'username', 'displayname'];
|
||||
|
||||
public function champion()
|
||||
{
|
||||
return $this->belongsTo(Champion::class);
|
||||
}
|
||||
|
||||
public function getPlatformAttribute($value): string
|
||||
{
|
||||
@@ -39,4 +37,9 @@ class Streamer extends Model
|
||||
'Huya' => "https://www.huya.com/{$this->username}",
|
||||
};
|
||||
}
|
||||
|
||||
public function champion(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Champion::class, 'champion_id', 'champion_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user