summaryrefslogtreecommitdiff
path: root/app/Rugby/Factory/Service.php
diff options
context:
space:
mode:
authorFbenas <philbeansburton@gmail.com>2020-06-21 17:58:23 +0100
committerFbenas <philbeansburton@gmail.com>2020-06-21 17:58:23 +0100
commit9cd0234665ea66dff172d94b9c1b4cb61b1d25b1 (patch)
tree9cb5d13acbf3c5bb8c842620ceb8a104b41babb7 /app/Rugby/Factory/Service.php
parent8d6e8b306d7836e4075a13ad98617bfe5afaa1a0 (diff)
Improve robustness of all scripts and add more to sync commandHEADmaster
Diffstat (limited to 'app/Rugby/Factory/Service.php')
-rw-r--r--app/Rugby/Factory/Service.php21
1 files changed, 21 insertions, 0 deletions
diff --git a/app/Rugby/Factory/Service.php b/app/Rugby/Factory/Service.php
index fa8028f..e966ce6 100644
--- a/app/Rugby/Factory/Service.php
+++ b/app/Rugby/Factory/Service.php
@@ -52,6 +52,27 @@ class Service
$away_team = Model\Team::Create(['name' => $data['team_away']]);
}
+ $existing_match = Model\Match::whereHas(
+ 'teams',
+ function ($query) use ($home_team) {
+ $query->where('name', '=', $home_team->name);
+ }
+ )->whereHas(
+ 'teams',
+ function ($query) use ($away_team) {
+ $query->where('name', '=', $away_team->name);
+ }
+ )->whereHas(
+ 'tournaments',
+ function ($query) use ($tournament) {
+ $query->where('name', '=', $tournament->name);
+ }
+ )->get();
+
+ if ($existing_match->first()) {
+ return;
+ }
+
$match = Model\Match::create(
[
'date' => (new \Carbon\Carbon($data['match_date']))->format('Y-m-d H:i:s'),