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
casperii
post
Post #2





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

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


Jeszcze pytanie takie z innej beczki.

Odnośnie kodu:

  1. protected function create(array $data)
  2. {
  3. // $data['id_user'] = rand(100, 999999999);
  4. $user = User::create([
  5. 'id_user' => 100,
  6. 'user' => $data['user'],
  7. 'email' => $data['email'],
  8. 'password' => bcrypt($data['password']),
  9. //'key' => Str::uuid()->toString(),
  10. ]);
  11.  
  12. return $user;
  13. }



czy do tablicy $data dane muszą tylko z zewnątrz (z pliku blade ) pochodzić ? Ponieważ jak wklepuje w ten (w powyższy) sposób to wyskakuje błąd:
  1. "SQLSTATE[HY000]: General error: 1364 Field 'id_user' doesn't have a default value

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: 7.10.2025 - 11:58