Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Laravel Rejestracja - tworzenie unikalnego identyfikatora usera, tworzenie unique id oraz sprawdzanie czy dany ID już nie istnieje.
casperii
post
Post #1





Grupa: Zarejestrowani
Postów: 681
Pomógł: 28
Dołączył: 14.08.2014

Ostrzeżenie: (0%)
-----


Panowie mam pytanie odnośnie zedytowania auth Laravela odnośnie rejestracji.
Obecny kod RegisterController.php

  1. namespace App\Http\Controllers\Auth;
  2.  
  3. use App\{User,Role};
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Foundation\Auth\RegistersUsers;
  7.  
  8. class RegisterController extends Controller
  9. {
  10.  
  11. use RegistersUsers;
  12.  
  13. protected $redirectTo = '/admin';
  14.  
  15. public function __construct()
  16. {
  17. $this->middleware('guest');
  18. }
  19.  
  20.  
  21. protected function validator(array $data)
  22. {
  23. return Validator::make($data, [
  24. 'user' => 'required|string|max:255',
  25. 'email' => 'required|string|email|max:255|unique:users',
  26. 'password' => 'required|string|min:6|confirmed',
  27. ]);
  28. }
  29.  
  30.  
  31. protected function create(array $data)
  32. {
  33. $user = User::create([
  34. 'user' => $data['user'],
  35. 'email' => $data['email'],
  36. 'password' => bcrypt($data['password']),
  37. ]);
  38.  
  39. // tu chciałbym dodać id_user = numer generowany
  40. }
  41. }


teraz do tego chciałbym dodać coś takiego w czystym php'ie by wyglądało tak:

  1.  
  2. $jest = false;
  3. do{
  4. $id_user = rand(0, 999999999);
  5. $id_user = str_repeat('0', 9-strlen($id_user)) . $id_user;
  6.  
  7. $result = 'SELECT count(`id_user`) FROM users WHERE id_user = '$id_user '
  8. $sql = mysql_query($result);
  9. $jest=mysql_num_rows($sql)>0;
  10. }
  11. while($jest);


Czy ktoś wie jak to połączyć ze sobą ? (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 559
Pomógł: 6315
Dołączył: 27.12.2004




Tak z czystej ciekawosci, bo musze chyba cos przegapiac:
czemu w twoim cudnym algorytmie losowosci ( (IMG:style_emoticons/default/wink.gif) ) masz
= str_repeat('0', 9-strlen($id_user))
czyli do kazdego wylosowanego usera dodajesz iles tam 0 ktore sa zalezne od wylosowanego id usera a przez to zawsze dla tego id usera beda takie same? Przeciez to juz nie dodaje zadnej unikalnosci
No chyba ze chciales poprostu zawsze miec te sama liczbe cyfr. No ale do tego uzywa sie str_pad() (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 10.10.2025 - 23:30