forked from metin2/web
Localized and coded character listing, view structure refactoring
This commit is contained in:
@ -3,8 +3,11 @@
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Enums\CharacterJobEnum;
|
||||
use App\Models\Game\Highscore\HighscoreCache;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class Player extends Model
|
||||
{
|
||||
@ -60,7 +63,7 @@ class Player extends Model
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
|
||||
'job' => CharacterJobEnum::class,
|
||||
];
|
||||
|
||||
/**
|
||||
@ -70,4 +73,20 @@ class Player extends Model
|
||||
{
|
||||
return $this->belongsTo(Account::class, 'account_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index of this player's account
|
||||
*/
|
||||
public function index(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(PlayerIndex::class, 'account_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this player's ranking
|
||||
*/
|
||||
public function highscore(): HasOne
|
||||
{
|
||||
return $this->hasOne(HighscoreCache::class, 'name', 'name');
|
||||
}
|
||||
}
|
||||
|
75
app/Models/Game/Player/PlayerIndex.php
Normal file
75
app/Models/Game/Player/PlayerIndex.php
Normal file
@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\Account;
|
||||
use App\Models\Enums\CharacterJobEnum;
|
||||
use App\Models\Enums\EmpireEnum;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PlayerIndex extends Model
|
||||
{
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'player';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'player_index';
|
||||
|
||||
/**
|
||||
* The primary key for the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'empire' => EmpireEnum::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the account that owns the player index.
|
||||
*/
|
||||
public function account(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Account::class, 'id', 'id');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user