32 lines
980 B
PHP
32 lines
980 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
/** What tribe_id holds towards other_tribe_id: a pact (once confirmed by both) or enmity. */
|
|
class TribeRelation extends Model
|
|
{
|
|
protected $guarded = [];
|
|
|
|
protected $dateFormat = 'Y-m-d H:i:s.v';
|
|
|
|
protected function casts(): array
|
|
{
|
|
return ['confirmed_at' => 'immutable_datetime', 'ends_at' => 'immutable_datetime'];
|
|
}
|
|
|
|
public function other(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Tribe::class, 'other_tribe_id');
|
|
}
|
|
|
|
/** @return array{tribe_id: int, other_tribe_id: int, state: string, confirmed: bool, ends_at: CarbonImmutable|null} */
|
|
public function row(): array
|
|
{
|
|
return ['tribe_id' => $this->tribe_id, 'other_tribe_id' => $this->other_tribe_id, 'state' => $this->state, 'confirmed' => $this->confirmed_at !== null, 'ends_at' => $this->ends_at];
|
|
}
|
|
}
|