Guest User

Untitled

a guest
Jan 27th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. 'second_database' => [
  2. 'driver' => env('DB_CONNECTION_2'),
  3. 'host' => env('DB_HOST_2'),
  4. 'port' => env('DB_PORT_2'),
  5. 'database' => env('DB_DATABASE_2'),
  6. 'username' => env('DB_USERNAME_2'),
  7. 'password' => env('DB_PASSWORD_2'),
  8. ],
  9.  
  10. //main database
  11. DB_CONNECTION=mysql
  12. DB_HOST=mysql.myhost.com
  13. DB_PORT=22
  14. DB_DATABASE=main_database
  15. DB_USERNAME=johnny
  16. DB_PASSWORD=pass123
  17.  
  18. //second database
  19. DB_CONNECTION_2=mysql
  20. DB_HOST_2=mysql.myhost.com
  21. DB_PORT_2=22
  22. DB_DATABASE_2=second_database
  23. DB_USERNAME_2=johnny
  24. DB_PASSWORD_2=pass123
  25.  
  26. //first approach
  27. DB::connection('second_database')->create('users', function($table){
  28. $table->email = $data['email'];
  29. $table->name = $data['name'];
  30. $table->password = 123123;
  31. $table->save();
  32. });
  33.  
  34. //other approach
  35. DB::connection('second_database')->table('users')->create([
  36. 'name' => $data['name'],
  37. 'email' => $data['email'],
  38. 'password' => Hash::make($data['password']),
  39. ]);
Add Comment
Please, Sign In to add comment