45 lines
987 B
PHP
45 lines
987 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
|
|
class Player extends Model
|
|
{
|
|
protected $guarded = [];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['protected_since' => 'immutable_datetime', 'last_active_at' => 'immutable_datetime'];
|
|
}
|
|
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public function world(): BelongsTo
|
|
{
|
|
return $this->belongsTo(World::class);
|
|
}
|
|
|
|
public function membership(): HasOne
|
|
{
|
|
return $this->hasOne(TribeMember::class);
|
|
}
|
|
|
|
/** The tribe the player belongs to, if any. */
|
|
public function tribeId(): ?int
|
|
{
|
|
return $this->membership?->tribe_id;
|
|
}
|
|
|
|
public function villages(): HasMany
|
|
{
|
|
return $this->hasMany(Village::class);
|
|
}
|
|
}
|