diff --git a/.gitignore b/.gitignore index d38ba36..5711796 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,5 @@ yarn-error.log /.vscode _ide_helper.php .phpstorm.meta.php + +_ide_helper_models.php diff --git a/app/Http/Controllers/ChampionController.php b/app/Http/Controllers/ChampionController.php index b0f582f..981e141 100644 --- a/app/Http/Controllers/ChampionController.php +++ b/app/Http/Controllers/ChampionController.php @@ -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]); } } diff --git a/app/Http/Controllers/StreamerPanelController.php b/app/Http/Controllers/StreamerPanelController.php index 14dcf1a..50f9041 100644 --- a/app/Http/Controllers/StreamerPanelController.php +++ b/app/Http/Controllers/StreamerPanelController.php @@ -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', diff --git a/app/Models/Champion.php b/app/Models/Champion.php index 3e9e49b..73576e5 100644 --- a/app/Models/Champion.php +++ b/app/Models/Champion.php @@ -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'; diff --git a/app/Models/Streamer.php b/app/Models/Streamer.php index f06e6c1..65f3e67 100644 --- a/app/Models/Streamer.php +++ b/app/Models/Streamer.php @@ -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'); + } } diff --git a/database/migrations/2024_03_20_233357_create_streamers_table.php b/database/migrations/2024_03_20_233357_create_streamers_table.php index a69f5d8..3ff4f58 100644 --- a/database/migrations/2024_03_20_233357_create_streamers_table.php +++ b/database/migrations/2024_03_20_233357_create_streamers_table.php @@ -13,11 +13,16 @@ return new class extends Migration { Schema::create('streamers', function (Blueprint $table) { $table->id(); - $table->foreignId('champion_id')->constrained(); + $table->integer('champion_id'); $table->enum('platform', ['twitch', 'youtube', 'kick', 'douyu', 'huya']); $table->string('username'); $table->string('displayname'); + + $table->foreign('champion_id')->references('champion_id')->on('champions')->onDelete('cascade'); + $table->timestamps(); + + }); } diff --git a/resources/views/champions/show.blade.php b/resources/views/champions/show.blade.php index f0f744e..b50ca14 100644 --- a/resources/views/champions/show.blade.php +++ b/resources/views/champions/show.blade.php @@ -5,7 +5,7 @@ about ' . $champion->name . ', ' . $champion->title . '. ' . substr($champion->lore, 0, 50) . '...') @section('content') - + @endsection @push('bottom_scripts') diff --git a/resources/views/components/champions/grid_info.blade.php b/resources/views/components/champions/grid_info.blade.php index a3d0421..87b8b91 100644 --- a/resources/views/components/champions/grid_info.blade.php +++ b/resources/views/components/champions/grid_info.blade.php @@ -5,125 +5,136 @@ CHAMPION DETAILS

- {{$champion->name}}

+ {{ $champion->name }}

- {{$champion->title}}

+ class="text-sm font-bold text-center text-transparent uppercase md:text-lg bg-gradient-to-bl from-orange-300 to-orange-500 bg-clip-text"> + {{ $champion->title }} -
-
+
+
-
-
- {{$champion->name}} Splash Art + class="relative border shadow-sm rounded-2xl bg-stone-800/40 border-neutral-300/5 shadow-stone-800/80 lg:col-span-2"> +
+
+ {{ $champion->name }} Splash Art
-
+

- {{$champion->name}} Information

+ {{ $champion->name }} Information
    -
  • - Full Title: {{$champion->name}}, {{$champion->title}}. +
  • + Full Title: {{ $champion->name }}, {{ $champion->title }}.
  • -
  • - Popular Positions: @foreach($champion->lanes->roles as $lane) - {{$lane}} @svg(getRoleIconSvg($lane), 'w-5 h-5 inline-block') - @if(!$loop->last) +
  • + Popular Positions: + @foreach ($champion->lanes->roles as $lane) + {{ $lane }} @svg(getRoleIconSvg($lane), 'w-5 h-5 inline-block') + @if (!$loop->last) - - @endif + @endif + @endforeach
  • -
  • Blue Essence Cost: - {{$champion->price_be}} BE + {{ $champion->price_be }} BE
  • -
  • Riot Points Cost: - {{$champion->price_rp}} RP + {{ $champion->price_rp }} RP
  • -
  • - Roles: @foreach($champion->roles as $role) - {{$role}} - @if(!$loop->last) +
  • + Roles: + @foreach ($champion->roles as $role) + {{ $role }} + @if (!$loop->last) - - @endif + @endif + @endforeach
  • -
  • +
  • Attack Type: {{$champion->attack_type}} + class="inline-block lowercase capitalize-first">{{ $champion->attack_type }}
  • -
  • - Damage Type: {{$champion->adaptive_type}} +
  • + Damage Type: {{ $champion->adaptive_type }}
  • -
  • - Resource Type: {{$champion->resource_type}} +
  • + Resource Type: {{ $champion->resource_type }}
  • -
  • +
  • Champion ID: {{$champion->champion_id}} + class="font-mono font-medium">{{ $champion->champion_id }}
  • -
  • - Release Date: {{$champion->release_date}} +
  • + Release Date: {{ $champion->release_date }}
  • -
  • - Release Patch: Patch {{$champion->release_patch}} +
  • + Release Patch: Patch {{ $champion->release_patch }}
-
+

- {{$champion->name}} Lore

-

- {{$champion->lore}} + {{ $champion->name }} Streamers +

+ A list of streamers who play {{ $champion->name }} and are atleast Diamond 2 or higher.

-
+
+ @foreach ($streamers as $streamer) + + @endforeach +
+ +
-
+

- {{$champion->name}} Skins ({{count($champion->skins)}})

+ {{ $champion->name }} Skins ({{ count($champion->skins) }})
- @foreach($champion->skins as $key => $skin) -
+
+
+

+ {{ $champion->name }} Lore

+

+ {{ $champion->lore }} +

+
+
diff --git a/resources/views/components/streamerpanel/streamer-create-form.blade.php b/resources/views/components/streamerpanel/streamer-create-form.blade.php index 0b84d38..4ca9336 100644 --- a/resources/views/components/streamerpanel/streamer-create-form.blade.php +++ b/resources/views/components/streamerpanel/streamer-create-form.blade.php @@ -3,9 +3,10 @@
- + @foreach ($champions as $champion) - + @endforeach
@@ -21,7 +22,8 @@
- +
diff --git a/resources/views/components/streamerpanel/streamers-table.blade.php b/resources/views/components/streamerpanel/streamers-table.blade.php index 06e184f..0a0f401 100644 --- a/resources/views/components/streamerpanel/streamers-table.blade.php +++ b/resources/views/components/streamerpanel/streamers-table.blade.php @@ -2,7 +2,6 @@ @endpush -