Exemple #1
0
 public function storeClub($data, $country, $season)
 {
     $location = Location::firstOrNew(['name' => $data['location'], 'country_id' => $country->id]);
     if ($country->locations()->where(['id' => $location->id])->get()->count() == 0) {
         $country->locations()->save($location);
     }
     $club = Club::firstOrNew(array('name' => $data['name'], 'location_id' => $location->id));
     $club->save();
     if ($this->clubs()->where('id', '=', $club->id)->wherePivot('season_id', '=', $season->id)->get()->count() == 0) {
         $this->clubs()->attach($club->id, ['berger_id' => $data['num'], 'season_id' => $season->id]);
     }
     return $club;
 }