mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 10:10:48 +01:00
feat: champion list
This commit is contained in:
@@ -13,7 +13,11 @@ class ChampionController extends Controller
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
$champions = Champion::orderBy('name')->get();
|
||||
|
||||
return view('champions.index', [
|
||||
'champions' => $champions,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@ use Cviebrock\EloquentSluggable\Sluggable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class Champion extends Model
|
||||
{
|
||||
@@ -46,11 +47,19 @@ class Champion extends Model
|
||||
return $this->hasMany(ChampionSkin::class);
|
||||
}
|
||||
|
||||
public function getChampionImageAttribute(): string
|
||||
public function lanes(): HasOne
|
||||
{
|
||||
return 'https://cdn.communitydragon.org/latest/champion/' . $this->champion_id . '/splash-art';
|
||||
return $this->hasOne(ChampionRoles::class, 'champion_id', 'champion_id');
|
||||
}
|
||||
|
||||
public function getChampionImageAttribute($centered = true): string
|
||||
{
|
||||
$url = 'https://cdn.communitydragon.org/latest/champion/' . $this->champion_id . '/splash-art';
|
||||
|
||||
return $centered ? $url . '/centered' : $url;
|
||||
}
|
||||
|
||||
|
||||
public function getChampionImageLoadingAttribute(): string
|
||||
{
|
||||
return 'https://cdn.communitydragon.org/latest/champion/' . $this->champion_id . '/portrait';
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ChampionRoles extends Model
|
||||
{
|
||||
@@ -19,9 +20,9 @@ class ChampionRoles extends Model
|
||||
'roles' => 'array',
|
||||
];
|
||||
|
||||
public function champion()
|
||||
public function champion(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Champion::class);
|
||||
return $this->belongsTo(Champion::class, 'champion_id', 'champion_id');
|
||||
}
|
||||
|
||||
public function getRolesAttribute($value): array
|
||||
@@ -46,4 +47,17 @@ class ChampionRoles extends Model
|
||||
|
||||
return $transformedRoles;
|
||||
}
|
||||
|
||||
public function getRoleIcon($roleName)
|
||||
{
|
||||
$roleIcons = [
|
||||
'Toplane' => 'gm-top.png',
|
||||
'Jungle' => 'gm-jungle.png',
|
||||
'Midlane' => 'gm-mid.png',
|
||||
'Botlane' => 'gm-bot.png',
|
||||
'Support' => 'gm-support.png',
|
||||
];
|
||||
|
||||
return asset('img/' . $roleIcons[$roleName]);
|
||||
}
|
||||
}
|
||||
|
||||
18
app/View/Components/Champions/List_all.php
Normal file
18
app/View/Components/Champions/List_all.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components\Champions;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class List_all extends Component
|
||||
{
|
||||
public function __construct(public array $champions)
|
||||
{
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('components.champions.list_all');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user