summaryrefslogtreecommitdiff
path: root/app/Rugby/Model/Team.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/Team.php
parentc83e876693bdb71c66418c13f5e09dfdaef24478 (diff)
Initial commit
Diffstat (limited to 'app/Rugby/Model/Team.php')
-rw-r--r--app/Rugby/Model/Team.php34
1 files changed, 34 insertions, 0 deletions
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 @@
+<?php
+
+namespace App\Rugby\Model;
+
+use Illuminate\Database\Eloquent\Model;
+
+use App\Rugby\Model\Match;
+
+class Team extends Model
+{
+ protected $table = 'teams';
+
+ protected $fillable = ['name'];
+
+ public function matches()
+ {
+ return $this->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 ?: '';
+ }
+}