From 9cd0234665ea66dff172d94b9c1b4cb61b1d25b1 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Sun, 21 Jun 2020 17:58:23 +0100 Subject: Improve robustness of all scripts and add more to sync command --- app/Rugby/Factory/Service.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'app/Rugby/Factory/Service.php') 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'), -- cgit v1.2.3