1

I have written a PHP based Web Application several years ago in Plain PHP. Now for some reason, I want to upgrade that project in Laravel. But I face a problem when I want to Laravel default authentication (which is done by php artisan make:auth).

Because, the old project uses user_account to store user info (username, password, and so on), but so far what I know, Laravel uses users table to store user information.

There is no way to rename user_account to users to solve the issue.

Is there any way to user_account in Laravel so that Laravel uses that table during login, registration, and so on..

  • Thanks

6 Answers 6

3

you can try with adding below line in your User Model(User.php).

protected $table = 'user_account';
Sign up to request clarification or add additional context in comments.

Comments

1

From Laravel Eloquent Model naming convention documentation:

By convention, the "snake case", plural name of the class will be used as the table name unless another name is explicitly specified. You may specify a custom table by defining a table property on your model:

protected $table = 'table_name';

So in your case you can go to the User model and override its default (plural name case) table binding and define:

protected $table = 'user_account';

I think this will solve your issue.

Comments

1

Simple and Sweet, Go to the User.php file (User Model)

protected $table = 'user_account';

Comments

1

You have change in a number of places to achieve this goal.

Model

update user model from app/User.php, if you have not changed the default path

protected $table = 'users';

Controller

on the RegisterContoller you need to update the validation rules, where it checks the unique email.

Comments

0

I have same problem like this. My problems is transfer data from Wordpress to java spring boot and problem is users table.So my solution is force to encrypt password in old project( Plain PHP) and used it on laravel project.

Comments

0

Try to go to the USER model and rename the table name to the one you want, adding this line:

protected $table = 'user_account';

This way I dont think you shouldn't need to change much of code, and you will change the default "users" name to your custom one.

You should also be able to modify the fields in the "protected $fillable" array. However I'm not sure if all of this has some issue in the core code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.