Reputation: 5007
I'm learning Laravel 5.6, and I want to be able to use my existing user
table which is present in another database. It's still called users, but it has lots and lots of data in it.
In order to achieve this I really need to do two things:
users
database in a different database to the default oneSo. For the point one I currently have my Laravel .env
database variables pointing to my test database, laravel
. What I'd like to is to just have the user lookup / authentication use the table users
in my shop
database. So instead of laravel.users
it would be shop.users
.
As I mentioned before I haven't been using great encryption but until I get round to properly encrypting everyones passwords I'd need Laravel to use my own encryption method, (which I know isnt as secure) But the hashing is as follows:
$hash = hash('sha256',$salt.$password.$salt);
Is this possible / how can I achieve these two things?
Upvotes: 0
Views: 324
Reputation: 5007
Just for reference, I've found the answer to my question by simply modifying the file \config\auth.php
. There was an array commented out that looked like this:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users2',
// ],
],
I un-commented out the sections and set the table to users2. That worked fine. However that was still loading from the same database. So I changed the table
string to: shop.users2
and it worked straight away.
Simple! I couldnt find any documentation on that though, but I am glad it worked.
Upvotes: 1
Reputation: 607
I'm also new to Laravel, but I'm pretty sure that the easiest way to achieve this is to import your existing shop database to the new Laravel database.
From what I've gathered, there isn't any official support for this but it should be quite simple to write a small script that transfers all the data from the old DB to the new one using regular php sql queries and just looping it all into the new one.
Or just use some unofficial package.
Upvotes: 1