public function storeReferee($data, $season, $type, $country) { $location = Location::firstOrNew(['name' => $data['location'], 'country_id' => $country->id]); if ($country->locations()->where(['id' => $location->id])->get()->count() == 0) { $country->locations()->save($location); } $ref = Person::firstOrNew(['first_name' => $data['name'], 'last_name' => $data['lname'], 'location_id' => $location->id]); $ref->parent_league = $data['league']; $ref->save(); if ($this->referees()->where('id', '=', $ref->id)->wherePivot('season_id', '=', $season->id)->wherePivot('type', '=', $type)->get()->count() == 0) { $this->referees()->attach($ref->id, ['pair_number' => $data['pivot']['pair_number'], 'season_id' => $season->id, 'type' => $type]); } if ($data['pivot']['pair_number'] != null) { $pair = $this->storePair($ref->id, $data['pivot']['pair_number'], $season->id, 1); $pair->active = 1; $pair->save(); } return $ref; }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $country = Country::firstOrNew(['name' => $data['country']]); $country->save(); $location = Location::firstOrNew(['name' => $data['location'], 'country_id' => $country->id]); if ($country->locations()->where(['id' => $location->id])->get()->count() == 0) { $country->locations()->save($location); } $person = Person::firstOrNew(['first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'location_id' => $location->id]); if ($location->person()->where(['id' => $person->id])->get()->count() == 0) { $location->person()->save($person); } return User::create(['person_id' => $person->id, 'email' => $data['email'], 'password' => bcrypt($data['password']), 'type' => 'member']); }