From d1fe4536cc039450b540104e382db0d01d5cf886 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Fri, 19 Jun 2020 02:16:51 +0100 Subject: Initial commit --- app/Rugby/Model/Match.php | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/Rugby/Model/Match.php (limited to 'app/Rugby/Model/Match.php') diff --git a/app/Rugby/Model/Match.php b/app/Rugby/Model/Match.php new file mode 100644 index 0000000..5447ef5 --- /dev/null +++ b/app/Rugby/Model/Match.php @@ -0,0 +1,59 @@ + 'datetime:Y-m-d']; + + protected $fillable = ['score', 'half_score', 'referee', 'date']; + + public function teams() + { + return $this->belongsToMany(Team::class, 'match_team'); + } + + public function venue() + { + return $this->hasOne(Venue::class, 'id'); + } + + public function getDisplayName() + { + $venue = Venue::find($this->venue_id); + + if (!$venue) { + return 'Unknown'; + } + + return $venue->name; + } + + public function getDisplayDate() + { + return (new \Carbon\Carbon($this->date))->format('M d Y'); + } + + public function homeTeam() + { + return $this->teams()->wherePivot('is_home', '=', true); + } + + public function awayTeam() + { + return $this->teams()->wherePivot('is_home', '=', false); + } + + public function tournaments() + { + return $this->belongsToMany(Tournament::class, 'match_tournament'); + } +} -- cgit v1.2.3