Files
HeimerdingerLoL/app/Models/ChampionRoles.php
2023-11-07 17:28:37 +01:00

64 lines
1.4 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ChampionRoles extends Model
{
use HasFactory;
protected $fillable = [
'champion_id',
'champion_name',
'roles',
];
protected $casts = [
'roles' => 'array',
];
public function champion(): BelongsTo
{
return $this->belongsTo(Champion::class, 'champion_id', 'champion_id');
}
public function getRolesAttribute($value): array
{
$value = json_decode($value);
$roleNames = [
'TOP' => 'Toplane',
'JUNGLE' => 'Jungle',
'MIDDLE' => 'Midlane',
'BOTTOM' => 'Botlane',
'UTILITY' => 'Support',
];
$transformedRoles = [];
foreach ($value as $role) {
if (isset($roleNames[$role])) {
$transformedRoles[] = $roleNames[$role];
}
}
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]);
}
}