php - Changing the location of the User Table in Laravel 5.6


I'm learning Laravel 5.6, and I want to be able to use my existinguser 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:

  • Have Laravel use theusers database in a different database to the default one
  • Change the method for encrypting passwords to my inferior way (until I actually get round to using bcrypt for all my users)

So. 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 tableusers in myshop database. So instead oflaravel.users it would beshop.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?




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.




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 thetable string to:shop.users2 and it worked straight away.

Simple! I couldnt find any documentation on that though, but I am glad it worked.

People are also looking for solutions to the problem: mysql - Display all entries in a table using for loop in PHP


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.