diff options
Diffstat (limited to 'app/Rugby/Factory/Service.php')
-rw-r--r-- | app/Rugby/Factory/Service.php | 21 |
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'), |