summaryrefslogtreecommitdiff
path: root/app/Rugby/Model/Match.php
diff options
context:
space:
mode:
authorFbenas <philbeansburton@gmail.com>2020-06-19 02:16:51 +0100
committerFbenas <philbeansburton@gmail.com>2020-06-19 02:16:51 +0100
commitd1fe4536cc039450b540104e382db0d01d5cf886 (patch)
treefd40ab48f79370541f377b59bb381811126485ad /app/Rugby/Model/Match.php
parentc83e876693bdb71c66418c13f5e09dfdaef24478 (diff)
Initial commit
Diffstat (limited to 'app/Rugby/Model/Match.php')
-rw-r--r--app/Rugby/Model/Match.php59
1 files changed, 59 insertions, 0 deletions
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 @@
+<?php
+
+namespace App\Rugby\Model;
+
+use App\Rugby\Model\Team;
+use App\Rugby\Model\Tournament;
+use App\Rugby\Model\Venue;
+
+use Illuminate\Database\Eloquent\Model;
+
+class Match extends Model
+{
+ protected $table = 'matches';
+
+ protected $casts = ['date' => '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');
+ }
+}