Files
2026-07-14 00:01:48 +03:00

38 lines
1.3 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Tribunal extends Model
{
protected $fillable = [
'anime_id', 'episode_id', 'created_by', 'question',
'side_a', 'side_b', 'extra_sides', 'status', 'verdict', 'closes_at',
];
protected $casts = [
'closes_at' => 'datetime',
'extra_sides' => 'array',
];
// Tüm tarafları ['a'=>'Haklıydı', 'b'=>'Haksızdı', 'c'=>'...'] formatında döndür
public function allSides(): array
{
$sides = ['a' => $this->side_a, 'b' => $this->side_b];
foreach (($this->extra_sides ?? []) as $i => $label) {
$sides[chr(99 + $i)] = $label; // c, d, e, ...
}
return $sides;
}
public function anime() { return $this->belongsTo(Anime::class); }
public function episode() { return $this->belongsTo(Episode::class); }
public function creator() { return $this->belongsTo(User::class, 'created_by'); }
public function votes() { return $this->hasMany(TribunalVote::class); }
public function arguments() { return $this->hasMany(TribunalArgument::class); }
public function voteCountA() { return $this->votes()->where('side', 'a')->count(); }
public function voteCountB() { return $this->votes()->where('side', 'b')->count(); }
}