Files
HeimerdingerLoL/app/Models/ChampionSkin.php
Rico van Zelst 6d2731f1d3 feat: Add functionality to retrieve champion images from the database
- Added a new function `getChampionImage` to fetch champion images based on ID and type.
- Created a new model `ChampionImage` to store champion image details in the database.
- Implemented seeding of champion images using `ChampionImageSeeder`.
- Updated usage of champion images in existing methods.
2024-05-02 00:50:51 +02:00

90 lines
2.2 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
{
return getChampionImage($this->full_skin_id, $uncentered ? 'uncentered_splash' : 'splash');
}
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;
}
}