mirror of
https://github.com/rico-vz/HeimerdingerLoL.git
synced 2025-12-06 10:10:48 +01:00
53 lines
1.1 KiB
PHP
53 lines
1.1 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;
|
|
}
|
|
|
|
|
|
}
|