/** * Returns a paginated country index. * * @param null|string $q * @return Paginator */ public function query($q = null) { return Country::where(function ($query) use($q) { if (strlen($q) == 2) { $query->orWhere('iso_code_2', '=', $q); } elseif ($q) { $query->where('name', 'like', "%{$q}%"); } })->orderBy('name')->paginate(); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { $user = User::create(['username' => $data['username'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]); if (isset($data['country'])) { $country = Country::where('code', $data['country'])->first(); $user->country()->associate($country); $user->save(); } return $user; }
/** * Show the application dashboard to the user. * * @return Response */ public function index() { if (Auth::user()) { $countryId = Auth::user()->country_id; } else { $location = GeoIPFacade::getLocation(); $countryId = Country::where('country_code', '=', $location['isoCode'])->first()->id; } $questions = Question::whereNotNull('questions.user_id')->whereNotNull('questions.question_category_id')->whereNotNull('questions.country_id')->where('questions.is_displayed', '=', 1)->where('questions.country_id', '=', $countryId)->where('questions_countries.country_id', '=', $countryId)->with('author')->with('category')->with('country')->join('questions_countries', 'questions.id', '=', 'questions_countries.question_id')->orderBy('questions_countries.count', 'DESC')->limit(5)->get(); $allQuestions = Question::orderBy('updated_at', 'DESC')->paginate(10); return view('pages.home', compact('questions', 'allQuestions')); }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ protected function create(array $data) { /** * Get the Country of User */ $geoip = \App::make('geoip'); $user_ip = \Input::getClientIp(); try { if ($user_geoip = $geoip->city($user_ip)) { $user_isoCode = $user_geoip->country->isoCode; $country = \App\Country::where('countryCode', 'LIKE', $user_isoCode)->first(); /** * Country returned is not in Countrie table */ if ($country == null) { $user_country_id = 0; } else { $user_country_id = $country->id; } } } catch (\Exception $e) { switch ($e) { case $e instanceof \InvalidArgumentException: $user_country_id = 0; break; case $e instanceof \GeoIp2\Exception\AddressNotFoundException: $user_country_id = 0; break; default: $user_country_id = 0; break; } } $confirmation_token = hash_hmac('sha256', str_random(40), $data['username']); $user = User::create(['username' => $data['username'], 'email' => $data['email'], 'name' => $data['name'], 'password' => bcrypt($data['password']), 'country_id' => $user_country_id, 'last_ipaddress' => $user_ip, 'confirmation_token' => $confirmation_token]); // Attach a role of Member to it. // Make sure your table named roles has Members row with Id of 5 // Or use $user->attachRole($member); with $member as a instance of Role $user->roles()->attach(5); /** * Fire event on User Register */ Event::fire(new UserRegistered($user)); /** * Return User to handle auto Login after Registration. */ return $user; }
/** * Run the database seeds. * * @return void */ public function run() { $date_id = \App\Date::where('date', '=', '2014-07-29')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2014-07-29-1270.jpg', 'caption' => 'Keylong, 2014', 'narrative' => 'Out for a stroll with Vortex, north towards Leh', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2014-07-23')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => "2014-07-23-1045.jpg", 'caption' => 'Brian Neill, 2014', 'narrative' => 'Beautiful, remote, wonderful...', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-10')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => "2013-06-10-0928.jpg", 'caption' => 'A Monastery', 'narrative' => '', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2014-07-23')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => "2014-07-23-1015.jpg", 'caption' => 'Brian Neill, 2014', 'narrative' => 'Beautiful, remote, wonderful...', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-09')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2013-06-09-0871.jpg', 'caption' => 'Leh', 'narrative' => 'once upon a time....', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-02')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2013-06-02-0157.jpg', 'caption' => 'Indian Railways', 'narrative' => 'On the narrow-gauge line at Jogindernagar.', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-07')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2013-06-07-0712.jpg', 'caption' => 'Prayer Flags', 'narrative' => 'The view from my breakfast table.', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-07')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2013-06-07-0749.jpg', 'caption' => 'Prayer Flags', 'narrative' => '', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-12')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2013-06-12-1101.jpg', 'caption' => 'Village wall, wood and sky', 'narrative' => '', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-14')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2013-06-14-1448.jpg', 'caption' => 'The road up to the Khardung La', 'narrative' => 'Getting high', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-15')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2013-06-15-1607.jpg', 'caption' => 'Khardung Village', 'narrative' => '', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-15')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2013-06-15-1625.jpg', 'caption' => 'Khardung Village', 'narrative' => '', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-16')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2013-06-16-1701.jpg', 'caption' => 'Clearing skies, from my hotel balconey', 'narrative' => '', 'date_id' => $date_id, 'country_id' => $country_id]); $date_id = \App\Date::where('date', '=', '2013-06-16')->pluck('id'); $country_id = \App\Country::where('country', '=', 'India')->pluck('id'); DB::table('images')->insert(['created_at' => Carbon\Carbon::now()->toDateTimeString(), 'updated_at' => Carbon\Carbon::now()->toDateTimeString(), 'filename' => '2013-06-16-1706.jpg', 'caption' => 'Sand dunes and scree, Hunder, Nubra Valley', 'narrative' => '', 'date_id' => $date_id, 'country_id' => $country_id]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $deleteChecked = Input::get('list'); if ($deleteChecked) { foreach ($deleteChecked as $delete) { $resumdel1 = Country::where('id', $delete)->delete(); } Session::flash('message', 'Successfully deleted'); } else { } return Redirect::to('country'); }
/** * @return bool * * Track all round record into Database. */ public function track() { /** * @var Game */ $game = new Game(); $game->tag = $this->roundTag; $game->server_time = $this->serverTime; $game->round_time = $this->timePlayed; $game->round_index = $this->roundIndex + 1 . " / " . $this->roundLimit; $game->gametype = $this->gameType; $game->outcome = $this->roundOutcome; $game->map_id = $this->gameMap; $game->total_players = $this->totalPlayers; $game->swat_score = $this->swatScore; $game->suspects_score = $this->suspectsScore; $game->swat_vict = $this->swatVictory; $game->suspects_vict = $this->suspectsVictory; if (!$game->save()) { return false; } /** * Iterate over each player array */ foreach ($this->players as $p) { /** * @var Player */ $player = new Player(); $player->ingame_id = $p[0]; $player->ip_address = $p[1]; $player->name = str_replace('(VIEW)', '', $p[5]); $player->name = str_replace('(SPEC)', '', $player->name); $player->team = array_key_exists(6, $p) ? $p[6] : 0; $player->is_admin = array_key_exists(3, $p) ? $p[3] : 0; $player->is_dropped = array_key_exists(2, $p) ? $p[2] : 0; $player->score = array_key_exists(8, $p) ? $p[8] : 0; $player->time_played = array_key_exists(7, $p) ? $p[7] : 0; $player->kills = array_key_exists(9, $p) ? $p[9] : 0; $player->team_kills = array_key_exists(10, $p) ? $p[10] : 0; $player->deaths = array_key_exists(11, $p) ? $p[11] : 0; $player->suicides = array_key_exists(12, $p) ? $p[12] : 0; $player->arrests = array_key_exists(13, $p) ? $p[13] : 0; $player->arrested = array_key_exists(14, $p) ? $p[14] : 0; $player->kill_streak = array_key_exists(15, $p) ? $p[15] : 0; $player->arrest_streak = array_key_exists(16, $p) ? $p[16] : 0; $player->death_streak = array_key_exists(17, $p) ? $p[17] : 0; $player->game_id = $game->id; $player_ip_trim = substr($p[1], 0, strrpos($p[1], ".")); $player_country_id = 0; $geoip = App::make('geoip'); try { if ($player_geoip = $geoip->city($player->ip_address)) { $player_isoCode = $player_geoip->country->isoCode; $country = Country::where('countryCode', 'LIKE', $player_isoCode)->first(); /** * Country returned is not in Countrie table */ if ($country == null) { $player_country_id = 0; } else { $player_country_id = $country->id; } } } catch (\Exception $e) { switch ($e) { case $e instanceof \InvalidArgumentException: $player_country_id = 0; break; case $e instanceof \GeoIp2\Exception\AddressNotFoundException: $player_country_id = 0; break; default: $player_country_id = 0; break; } } $loadout_array = array_key_exists(39, $p) ? $p[39] : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; /** * @var Loadout * * Create or find and return instance of Loadout and save to database. */ $loadout = Loadout::firstOrCreate(['primary_weapon' => array_key_exists(0, $loadout_array) ? $loadout_array[0] : 0, 'primary_ammo' => array_key_exists(1, $loadout_array) ? $loadout_array[1] : 0, 'secondary_weapon' => array_key_exists(2, $loadout_array) ? $loadout_array[2] : 0, 'secondary_ammo' => array_key_exists(3, $loadout_array) ? $loadout_array[3] : 0, 'equip_one' => array_key_exists(4, $loadout_array) ? $loadout_array[4] : 0, 'equip_two' => array_key_exists(5, $loadout_array) ? $loadout_array[5] : 0, 'equip_three' => array_key_exists(6, $loadout_array) ? $loadout_array[6] : 0, 'equip_four' => array_key_exists(7, $loadout_array) ? $loadout_array[7] : 0, 'equip_five' => array_key_exists(8, $loadout_array) ? $loadout_array[8] : 0, 'breacher' => array_key_exists(9, $loadout_array) ? $loadout_array[9] : 0, 'body' => array_key_exists(10, $loadout_array) ? $loadout_array[10] : 0, 'head' => array_key_exists(11, $loadout_array) ? $loadout_array[11] : 0]); /** * Create or find and return instance of Alias. */ $alias = Alias::firstOrNew(['name' => $player->name]); /** * If Alias is not present then new instance is created. */ if ($alias->id == null) { //$profile = Profile::firstOrNew(['ip_address' => $player_ip_trim.'%']); $profile = Profile::where('ip_address', 'LIKE', $player_ip_trim . '%')->first(); // If no profile present create new else ignore. if (!$profile) { $profile = new Profile(); } /** * Neither Alias not Profile is present. * * So it will create both new Alias and Profile. */ if ($profile->id == null) { $profile->name = $player->name; $profile->team = $player->team; $profile->country_id = $player_country_id; $profile->loadout_id = $loadout->id; $profile->game_first = $game->id; $profile->game_last = $game->id; $profile->ip_address = $player->ip_address; $profile->save(); $alias->name = $player->name; $alias->profile_id = $profile->id; $alias->ip_address = $player->ip_address; $alias->save(); } else { $alias->name = $player->name; $alias->profile_id = $profile->id; $alias->ip_address = $player->ip_address; $alias->save(); $profile->team = $player->team; $profile->game_last = $game->id; $profile->loadout_id = $loadout->id; $profile->ip_address = $player->ip_address; $profile->country_id = $player_country_id; $profile->save(); } } else { $profile = Profile::find($alias->profile_id); $profile->team = $player->team; $profile->game_last = $game->id; $profile->loadout_id = $loadout->id; $profile->ip_address = $player->ip_address; $profile->country_id = $player_country_id; $profile->save(); $alias->ip_address = $player->ip_address; $alias->save(); } $player->alias_id = $alias->id; $player->loadout_id = $loadout->id; $player->country_id = $player_country_id; $player->save(); /** * Iterate over all Weapon of each Player if exists */ if (array_key_exists(40, $p)) { foreach ($p[40] as $w) { $weapon = new Weapon(); $weapon->name = $w[0]; $weapon->player_id = $player->id; $weapon->seconds_used = array_key_exists(1, $w) ? $w[1] : 0; $weapon->shots_fired = array_key_exists(2, $w) ? $w[2] : 0; $weapon->shots_hit = array_key_exists(3, $w) ? $w[3] : 0; $weapon->shots_teamhit = array_key_exists(4, $w) ? $w[4] : 0; $weapon->kills = array_key_exists(5, $w) ? $w[5] : 0; $weapon->teamkills = array_key_exists(6, $w) ? $w[6] : 0; $weapon->distance = array_key_exists(7, $w) ? $w[7] : 0; $weapon->save(); } } } //$pt = new App\Server\Repositories\PlayerTotalRepository(); //$pt->calculate(); //$response = Response::make("0\\nStats has been successfully tracked",200); printf("%s", "0\nRound report tracked."); exit(0); }
/** * Remove a country from storage. * * @param int $id * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ public function destroyCountry($id) { Country::where('id', $id)->delete(); Session::flash('success_message', 'Country has been deleted from database'); return redirect('config'); }
public function country() { $country = Country::where('id', $this->countryID)->get(); return $country; }
public function ClearUpVariables($data, $hour_stamp) { //amend values as I wish $data['hour_stamp'] = $hour_stamp; $data['hour_stamp_flight_number'] = str_replace(' ', '', $hour_stamp . $data['flight_number']); //unique column $data['scheduled_time'] = Carbon::createFromFormat('d.m. H:i', $data['scheduled_time']); //airline code preg_match("|^..|", $data['flight_number'], $output_array_3); $data['airline_code'] = strtolower($output_array_3[0]); if ($data['airline_code'] == "ez") { $data['airline_code'] = "u2"; } //easyjet not using their IATA code U2 but EZY - manual correction //terminal preg_match("|[1-9]|", $data['terminal'], $output_array_4); $data['terminal'] = $output_array_4[0]; //destination $data['destination'] = strtolower($data['destination']); //keep all such data in lowercase (because Sqlite differentiate between Capitals and lower) preg_match("|(.*)\\((.*)\\)|", $data['destination'], $output_array_1); if (count($output_array_1) > 1) { $CitySlashAirport = $output_array_1[1]; $data['country_code'] = $output_array_1[2]; } else { $CitySlashAirport = null; $data['country_code'] = 'xx'; } unset($data['destination']); //in case some strange codes comes $country = Country::where('country_code', $data['country_code']); if (count($country) == 0) { $newcountry = new Country(); $newcountry->country_code = $data['country_code']; $newcountry->country_name = 'Undefined'; $newcountry->save(); } $output_array_2 = preg_split("|\\/|", $CitySlashAirport); $data['city'] = $output_array_2[0]; if (empty($data['city'])) { $data['city'] = 'empty'; } if (count($output_array_2) > 1) { $data['airport'] = $output_array_2[1]; } else { $data['airport'] = null; } //city_slug $slug = new SlugClass(); $data['city_slug'] = $slug->slugify($data['city']); //find if this city_slug is in cities table $city_slug_in_cities = City::where('city_slug', $data['city_slug'])->first(); if (empty($city_slug_in_cities)) { $city_slug_bridge = Slug::where('city_slug_dirty', $data['city_slug'])->first(); if (!empty($city_slug_bridge)) { $data['city_slug'] = $city_slug_bridge->city_slug_clean; echo $data['city_slug']; } } $data = array_map('trim', $data); //trim values return $data; }
public function findCountryByCode($countryCode) { return Country::where('country_code', $countryCode)->first(); }
public function country($country) { $this_country = Country::where('country_slug', $country)->first(); $cities = Flight::with('country')->whereHas('country', function ($query) use($country) { $query->where('country_slug', $country); })->where('scheduled_time', '>', Carbon::now()->subMonths(1))->groupBy('city', 'asc')->get(); $airlines = Flight::with('country')->whereHas('country', function ($query) use($country) { $query->where('country_slug', $country); })->where('scheduled_time', '>', Carbon::now()->subMonths(1))->where('codeshare', 0)->orderBy('airline', 'asc')->groupBy('airline')->get(); $arrivals = Flight::with('country')->whereHas('country', function ($query) use($country) { $query->where('country_slug', $country); })->where('codeshare', 0)->where('arrival', 1)->orderBy('scheduled_time', 'desc')->take(15)->get(); $departures = Flight::with('country')->whereHas('country', function ($query) use($country) { $query->where('country_slug', $country); })->where('codeshare', 0)->where('departure', 1)->orderBy('scheduled_time', 'desc')->take(15)->get(); return view('pages.country')->with(['this_country' => $this_country, 'cities' => $cities, 'airlines' => $airlines, 'arrivals' => $arrivals, 'departures' => $departures]); }
public function hash(Request $request, $key) { $link = DB::table('keys')->where('key', '=', $key)->get(); if ($link) { $current_ip = $request->getClientIp(); $test = app('Illuminate\\Routing\\UrlGenerator')->previous(); // $name = $this->get_title($test); $name = 'google.com'; $location = GeoIPFacade::getLocation('202.142.69.126'); $os_info = parser::detect(); //City data if (!City::where('city_name', $location['city'])->count()) { $city = new City(); $city_id = $city->insertGetId(['city_name' => $location['city']]); } else { $city_id = City::where('city_name', $location['city'])->value('id'); } //Country Data if (!Country::where('country_name', $location['country'])->count()) { $country = new Country(); $country_id = $country->insertGetId(['country_name' => $location['country']]); } else { $country_id = Country::where('country_name', $location['country'])->value('id'); } //Os Data if (!Operating_system::where('operating_system', $os_info['osFamily'])->count()) { $os = new Operating_system(); $os_id = $os->insertGetId(['operating_system' => $os_info['osFamily']]); } else { $os_id = Operating_system::where('operating_system', $os_info['osFamily'])->value('id'); } //Browser_data if (!Browser::where('browser_name', $os_info['browserFamily'])->count()) { $browser = new Browser(); $browser_id = $browser->insertGetId(['browser_name' => $os_info['browserFamily']]); } else { $browser_id = Browser::where('browser_name', $os_info['browserFamily'])->value('id'); } //Redirected Website data $website_hits = new Redirected_websites(); $website_hits->user_id = $link[0]->user_id; $website_hits->url_id = $link[0]->id; $website_hits->city_id = $city_id; $website_hits->country_id = $country_id; $website_hits->website_url = $test; $website_hits->website_name = $name; $website_hits->browser_id = $browser_id; $website_hits->os_id = $os_id; $website_hits->is_mobile = $os_info['isMobile']; $website_hits->is_tablet = $os_info['isTablet']; $website_hits->is_desktop = $os_info['isDesktop']; //Hits data $data = new Hit(); $data->url_ip = $current_ip; $data->url_id = $link[0]->id; $data->save(); $website_hits->save(); //Deep linking if (parser::isMobile()) { if (parser::osFamily() == 'Apple iOS') { //link for apple store } elseif (parser::osFamily() == 'Windows') { return redirect('https://www.microsoft.com/en-us/store/apps/google/9wzdncrfhx3w'); } elseif (parser::osFamily() == 'Blackberry') { //link for blackberry store } elseif (parser::osFamily() == 'AndroidOS') { return redirect('https://play.google.com/store/apps/details?id=com.facebook.katana&hl=en'); } } if (parser::isMobile()) { if (parser::osFamily() == 'Apple iOS') { //link for apple store } elseif (parser::osFamily() == 'Windows') { return redirect('https://www.microsoft.com/en-us/store/apps/google/9wzdncrfhx3w'); } elseif (parser::osFamily() == 'Blackberry') { //link for blackberry store } elseif (parser::osFamily() == 'AndroidOS') { return redirect('https://play.google.com/store/apps/details?id=com.facebook.katana&hl=en'); } } else { return redirect($link[0]->url); } } else { return redirect('/'); } }
public function voiceCall(Request $request) { $data = $request->all(); if (isset($data['id'])) { Response::json(array("status" => 'failure', "msg" => 'Missing argument')); } $regDetails = RegistrationDetails::find($data['id']); if (!$regDetails) { return Response::json(array("status" => "failure", "msg" => "No data is present")); } $phone_no = $regDetails->phone_no; $country = $regDetails->country; if (!$country) { return Response::json(array("status" => "failure", "msg" => "Country missing")); } $countryData = Country::where('name', "LIKE", $country)->first(); $phnCode = $countryData->phonecode; $phone = "+" . $phnCode . $phone_no; $mCode = $this->generateRandomString(4); $array = str_split($mCode); $regDetails->mobile_code = $mCode; $regDetails->save(); $twilio = Twilio::call($phone, $_ENV['app_url'] . "/callForMobileCode/{$array['0']}/{$array['1']}/{$array['2']}/{$array['3']}"); }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create($country_id) { $countries = Country::where('id', '=', $country_id)->get(); $languages = Language::all(); return view('createCity', ['countries' => $countries, 'languages' => $languages, 'country_id' => $country_id]); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $validator = \Validator::make($request->all(), ['ip_address' => 'required|ip|max:255', 'join_port' => 'required|numeric|min:0|max:65535', 'query_port' => 'required|numeric|min:0|max:65535']); if ($validator->fails()) { return \Redirect::back()->with('errors', $validator->errors())->withInput(); } if ($this->is_server_registered($request)) { return \Redirect::back()->with('error', "Server already registered")->withInput(); } try { $server = new Swat4Server($request->ip_address, $request->query_port); $server->query(); } catch (\Exception $e) { return \Redirect::back()->with('error', "Unable to query Server. Are you sure it is live ?")->withInput(); } $server = json_decode($server); if ($server->hostname == "...server is reloading or offline") { return \Redirect::back()->with('error', "Unable to query Server. Are you sure it is live ?")->withInput(); } /** * Get the Country of Server */ $geoip = \App::make('geoip'); $server_ip = $request->ip_address; try { if ($server_geoip = $geoip->city($server_ip)) { $server_isoCode = $server_geoip->country->isoCode; $country = \App\Country::where('countryCode', 'LIKE', $server_isoCode)->first(); /** * Country returned is not in Countrie table */ if ($country == null) { $server_country_id = 0; } else { $server_country_id = $country->id; } } } catch (\Exception $e) { switch ($e) { case $e instanceof \InvalidArgumentException: $server_country_id = 0; break; case $e instanceof \GeoIp2\Exception\AddressNotFoundException: $server_country_id = 0; break; default: $server_country_id = 0; break; } } $newServer = new Server(); $newServer->ip_address = $request->ip_address; $newServer->join_port = $request->join_port; $newServer->query_port = $request->query_port; $newServer->description = $request->description == '' ? NULL : $request->description; $newServer->hostname = $server->hostname; $newServer->country_id = $server_country_id; $newServer->submitter_id = \Auth::user()->id; $newServer->save(); return \Redirect::back()->with('message', "Server has been submitted!"); }
/** * Get the country by its full name. * * @param string $name * * @return Collection */ public function byName($name) { return Country::where('name', $name)->first(); }
/** * Handle Ban getting from Server * * @param InputRequest $request */ public function handlebans(InputRequest $request) { $successResponse = false; \Log::info($request->ban); if (!$request->has('ban') || !$request->has('key') || $request->get('key') != env('SERVER_QUERY_KEY')) { printf("ERROR: Invalid Response!"); exit(0); } $banList = $request->get('ban'); foreach ($banList as $ban) { $ban = explode(" \$ ", $ban); $type = $ban[0]; if ($type == "ban") { $ip_address = $ban[1]; $name = $ban[2]; $name = str_replace('(VIEW)', '', $name); $name = str_replace('(SPEC)', '', $name); $admin = $ban[3]; $admin = str_replace('(VIEW)', '', $admin); $admin = str_replace('(SPEC)', '', $admin); $admin_ip = $ban[4]; $reason = $ban[5] == "" ? null : $ban[5]; $banQ = Ban::findOrNullByIP($ip_address); // If no ban for this IP at Server then do add Ban. if ($banQ == null) { $player_country_id = 0; $geoip = \App::make('geoip'); try { $ip_without_mask = str_replace('*', '0', $ip_address); if ($player_geoip = $geoip->city($ip_without_mask)) { $player_isoCode = $player_geoip->country->isoCode; $country = Country::where('countryCode', 'LIKE', $player_isoCode)->first(); /** * Country returned is not in Countrie table */ if ($country == null) { $player_country_id = 0; } else { $player_country_id = $country->id; } } } catch (\Exception $e) { switch ($e) { case $e instanceof \InvalidArgumentException: $player_country_id = 0; break; case $e instanceof \GeoIp2\Exception\AddressNotFoundException: $player_country_id = 0; break; default: $player_country_id = 0; break; } } $newBan = Ban::create(['name' => $name, 'ip_address' => $ip_address, 'server_id' => 1, 'country_id' => $player_country_id, 'reason' => $reason, 'admin_name' => $admin, 'admin_ip' => $admin_ip, 'status' => true]); } else { if (!$banQ->status) { $banQ->name = $name; $banQ->status = true; $banQ->banned_till = null; $banQ->reason = $ban[5] == "" ? $banQ->reason : $ban[5]; $banQ->updated_by = $admin; $banQ->updated_by_site = false; $banQ->save(); } } $successResponse = true; } else { if ($type == "unban") { $ip_address = $ban[1]; $admin = $ban[2]; $admin = str_replace('(VIEW)', '', $admin); $admin = str_replace('(SPEC)', '', $admin); $banQ = Ban::findOrNullByIP($ip_address); if ($banQ && $banQ->status) { $banQ->status = false; $banQ->banned_till = Carbon::now(); $banQ->updated_by = $admin; $banQ->updated_by_site = false; $banQ->save(); } $successResponse = true; } } } if ($successResponse) { print "SUCCESS"; exit(0); } }