mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 10:10:48 +01:00
- Refactored the logic for generating image URLs for champions and champion skins to improve readability and maintainability.
94 lines
2.5 KiB
PHP
94 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Cviebrock\EloquentSluggable\Sluggable;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class ChampionSkin extends Model
|
|
{
|
|
use HasFactory;
|
|
use Sluggable;
|
|
|
|
protected $fillable = [
|
|
'champion_id',
|
|
'full_skin_id',
|
|
'skin_id',
|
|
'skin_name',
|
|
'lore',
|
|
'availability',
|
|
'loot_eligible',
|
|
'rp_price',
|
|
'raritiy',
|
|
'release_date',
|
|
'associated_skinline',
|
|
'new_effects',
|
|
'new_animations',
|
|
'new_recall',
|
|
'new_voice',
|
|
'new_quotes',
|
|
'voice_actor',
|
|
'splash_artist',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'associated_skinline' => 'array',
|
|
'voice_actor' => 'array',
|
|
'splash_artist' => 'array',
|
|
];
|
|
}
|
|
|
|
public function sluggable(): array
|
|
{
|
|
return [
|
|
'slug' => [
|
|
'source' => 'skin_name',
|
|
],
|
|
];
|
|
}
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'slug';
|
|
}
|
|
|
|
public function getRarityAttribute($value)
|
|
{
|
|
return $value === null || $value === 'NoRarity' ? 'Common' : $value;
|
|
}
|
|
|
|
public function champion(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Champion::class, 'champion_id', 'champion_id');
|
|
}
|
|
|
|
public function chromas(): HasMany
|
|
{
|
|
return $this->hasMany(SkinChroma::class, 'full_skin_id', 'full_skin_id');
|
|
}
|
|
|
|
public function getSkinImageAttribute(bool $uncentered = false): string
|
|
{
|
|
$championName = strtolower(str_replace([' ', "'"], ['', ''], $this->champion->name));
|
|
$imagePath = $uncentered ? 'uncentered_' : 'centered_';
|
|
$imageUrl = 'https://raw.communitydragon.org/pbe/plugins/rcp-be-lol-game-data/global/default/assets/characters/' . $championName . '/skins/skin' . str_pad($this->skin_id, 2, '0', STR_PAD_LEFT) . '/images/' . $championName . '_splash_' . $imagePath . $this->skin_id . '.jpg';
|
|
|
|
return $imageUrl;
|
|
}
|
|
|
|
public function getSkinImageLoadingAttribute(): string
|
|
{
|
|
return 'https://cdn.communitydragon.org/latest/champion/'.$this->champion_id.'/portrait/skin/'.$this->skin_id;
|
|
}
|
|
|
|
public function getSkinImageTileAttribute(): string
|
|
{
|
|
return 'https://cdn.communitydragon.org/latest/champion/'.$this->champion_id.'/tile/skin/'.$this->skin_id;
|
|
}
|
|
}
|