Hello i'm having an error during registration of a new user. I have two database connections: first(default) oracle db for get data, second mysql db for users login, registration.
So i setup in database.php the default to oracle (so i don't have to use connection() method everytime).
In model User.php i put this line of code, so the login is pointing to mysql and i can login
protected $connection = 'mysql';
Everything is working fine until i try to register another user - i get an error because the registration is pointing to default oracle db. I could avoid this problem by switching the default again to mysql, but it's not the way i need.
What else i'm missing? How to point the registration to mysql db?
In database.php 'default' => env('DB_CONNECTION_ORA', 'oracle'),
I tried to add connection('mysql') on Schema user creation but it's still pointing the default.
RegisterController.php
class RegisterController extends Controller
{
Register Controller
use RegistersUsers;
protected $redirectTo = RouteServiceProvider::HOME;
protected $connection = 'mysql';
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\Models\User
*/
protected function create(array $data)
{
return User::connection('mysql')->create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
}