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 21.05.2019, 21:35:37
Post #1





Grupa: Zarejestrowani
Postów: 680
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ą ? smile.gif
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Pyton_000
post 22.05.2019, 19:08:25
Post #2





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


User::create towrzy encję User na danych z tablicy, zapisuje i zwraca obiekt.
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 Wersja Lo-Fi Aktualny czas: 25.04.2024 - 03:36