/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $users = User::all();
     $watchlists = Watchlist::all();
     foreach ($users as $user) {
         $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']);
     }
 }
 /**
  * @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');
 }
 /**
  * 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!');
     }
 }