Exemplo n.º 1
0
 /**
  * Show free usernames of a certain length
  *
  * @param Request $request
  * @param int $length
  * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function index(Request $request, $length = 1)
 {
     if (TwitterUser::whereUsernameLength($length)->count() == 0 && $length > 1) {
         return redirect('/');
     }
     $users = TwitterUser::free()->whereUsernameLength($length)->get();
     $last = null;
     if ($users->isEmpty() && TwitterUser::notRetrieved()->whereUsernameLength($length)->count() == 0) {
         $last = TwitterUser::whereUsernameLength($length)->orderBy('date_registered', 'DESC')->first();
     }
     $lengths = TwitterUser::selectUsernameLength()->orderBy('length')->groupBy('length')->get()->pluck('length')->toArray();
     return view('home')->withUsers($users)->withLengths($lengths)->withLength((int) $length)->withLast($last);
 }
 /**
  * Decides of any more usernames should be added to the database
  * Will add more if any more of the same length need to be added
  * Won't add more if above condition passes and there are some usernames still to check or some available usernames
  *
  * @return bool
  */
 private function populateMoreUsernames()
 {
     $currentLength = TwitterUser::select(DB::raw('MAX(CHAR_LENGTH(username)) as Max'))->pluck('Max');
     if (is_null($currentLength) || !TwitterUser::whereUsername(str_repeat('_', $currentLength))->exists()) {
         return true;
     }
     if (TwitterUser::neverQueried()->count() > 0 || TwitterUser::free()->count() > 0) {
         return false;
     }
     return true;
 }