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 ++++++++++++++++++++++++++++++++++++++++++ app/Rugby/Model/Team.php | 34 ++++++++++++++++++++++++ app/Rugby/Model/Tournament.php | 19 ++++++++++++++ app/Rugby/Model/Venue.php | 17 ++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 app/Rugby/Model/Match.php create mode 100644 app/Rugby/Model/Team.php create mode 100644 app/Rugby/Model/Tournament.php create mode 100644 app/Rugby/Model/Venue.php (limited to 'app/Rugby/Model') 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'); + } +} diff --git a/app/Rugby/Model/Team.php b/app/Rugby/Model/Team.php new file mode 100644 index 0000000..2582f33 --- /dev/null +++ b/app/Rugby/Model/Team.php @@ -0,0 +1,34 @@ +belongsToMany(Match::class)->withPivot('is_home'); + } + + public function homeMatches() + { + return $this->matches()->wherePivot('is_home', '=', true); + } + + public function awayMatches() + { + return $this->matches()->wherePivot('is_home', '=', false); + } + + public function getName() + { + return $this->name ?: ''; + } +} diff --git a/app/Rugby/Model/Tournament.php b/app/Rugby/Model/Tournament.php new file mode 100644 index 0000000..64d9a45 --- /dev/null +++ b/app/Rugby/Model/Tournament.php @@ -0,0 +1,19 @@ +belongsToMany(Match::class); + } +} diff --git a/app/Rugby/Model/Venue.php b/app/Rugby/Model/Venue.php new file mode 100644 index 0000000..be85c23 --- /dev/null +++ b/app/Rugby/Model/Venue.php @@ -0,0 +1,17 @@ +belongsToMany(Match::class); + } +} -- cgit v1.2.3