Ejemplo n.º 1
0
 public function printDistances($locations)
 {
     foreach ($locations as $item) {
         $response = GeoLocation::getGeocodeFromGoogle($item);
         $latitude = $response->results[0]->geometry->location->lat;
         $longitude = $response->results[0]->geometry->location->lng;
         $distance = Distance::between($latitude, $longitude, $this->currentLocation->latitude, $this->currentLocation->longitude);
         echo "Distance between {$this->currentLocation->city} and {$item} = " . $distance . "km<br>";
     }
 }
Ejemplo n.º 2
0
 /**
  * Bootstrap any application services.
  *
  * @return void
  */
 public function boot()
 {
     //Set user's longitude and latitude on saving (update and create)
     User::saving(function ($user) {
         try {
             $response = GeoLocation::getGeocodeFromGoogle($user->address);
             $user->latitude = $response->results[0]->geometry->location->lat;
             $user->longitude = $response->results[0]->geometry->location->lng;
         } catch (\Exception $e) {
             throw new InvalidAddressException("It seems that your address is missing or invalid. Please don't forget to set it on your Github profile if you are using Github Authentication.");
             // return false;
         }
     });
 }
 /**
  * @param Request $request
  */
 public function postRegister(UserCreateRequest $request)
 {
     $response = GeoLocation::getGeocodeFromGoogle($request->get('location'));
     $user = new User();
     $user->name = $request->get('name');
     $user->username = str_slug($request->get('username'), '_');
     $user->email = $request->get('email');
     $user->password = bcrypt($request->get('password'));
     $user->location = $request->get('location');
     $user->latitude = $response->results[0]->geometry->location->lat;
     $user->longitude = $response->results[0]->geometry->location->lng;
     $user->save();
     $user->createWatchlist(['title' => $user->username . ' follows', 'description' => $user->username . '_follow', 'type' => 'follow']);
     $watchlist = Watchlist::where('author_id', $user->id)->first();
     $watchlist->addItem(User::find(1));
     $user->createWatchlist(['title' => $user->username . '´s Bookmarks', 'description' => $user->username . '_bookmarks', 'type' => 'bookmarks']);
     Auth::login($user, true);
     event(new UserRegistered($user));
     alert()->success('You have successfully signed up', 'Welcome aboard!');
     return redirect()->intended('home');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $user = User::find($id);
     $response = GeoLocation::getGeocodeFromGoogle($request->get('location'));
     //        dd($request);
     $user->update($request->all());
     $user->latitude = $response->results[0]->geometry->location->lat;
     $user->longitude = $response->results[0]->geometry->location->lng;
     $user->save();
     alert()->success($user->username . ' was successfully updated', 'Alright!');
     return redirect()->intended('backend/users');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request)
 {
     //        $id = $id == Auth::user()->id;
     $user = Auth::user();
     if (Auth::check()) {
         //        dd($request);
         if ($request->has('location')) {
             $response = GeoLocation::getGeocodeFromGoogle($request->get('location'));
             $user->latitude = $response->results[0]->geometry->location->lat;
             $user->longitude = $response->results[0]->geometry->location->lng;
             $user->update($request->all());
         } else {
             $user->update($request->all());
         }
         //            dd($user);
         alert()->success('Your profile was successfully updated', 'Alright!');
         return redirect()->intended('account/profile');
     }
 }
 /**
  * Return user if exists; create and return if doesn't
  *
  * @param $githubUser
  * @return User
  */
 private function findOrCreateUser($githubUser)
 {
     if ($authUser = User::where('github_id', $githubUser->id)->first()) {
         return $authUser;
     } else {
         $response = GeoLocation::getGeocodeFromGoogle($githubUser->user['location']);
         $user = new User();
         $user->name = $githubUser->name;
         $user->username = str_slug($githubUser->nickname, '_');
         $user->email = $githubUser->email;
         $user->github_id = $githubUser->id;
         $user->avatar = $githubUser->avatar;
         $user->location = $githubUser->user['location'];
         $user->github_profile = $githubUser->user['html_url'];
         $user->hireable = $githubUser->user['hireable'];
         $user->website = $githubUser->user['blog'];
         $user->latitude = $response->results[0]->geometry->location->lat;
         $user->longitude = $response->results[0]->geometry->location->lng;
         $user->save();
         $user->createWatchlist(['title' => $user->username . ' follows', 'description' => $user->username . '_follow', 'type' => 'follow']);
         $watchlist = Watchlist::where('author_id', $user->id)->first();
         $watchlist->addItem(User::find(1));
         $user->createWatchlist(['title' => $user->username . '´s Bookmarks', 'description' => $user->username . '_bookmarks', 'type' => 'bookmarks']);
         Auth::login($user, true);
         event(new UserRegistered($user));
         alert()->success('You have successfully signed up', 'Welcome aboard!');
     }
 }