I am using Laravel Auth to register and login my users into the respective dashboard. I am using admin as my user
. I created the migration for admin, but when i try to register my admin error comes Table or view not found
and the table which is not found is the built in table users which i deleted because i was not using that one. I have to use the admin table please help me how can i remove this error.
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'fyp.users' doesn't exist (SQL: select count() as aggregate from users where email =**********)
There may be some possibilities that i have mention below:
1) In the config/auth.php change the users model to your company class.
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Admin::class,
],
2) In the Admin class, define fillable and hidden fields:
class Admin extends Authenticatable {
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
}
3) Do not forget to change validation in registerContoller.
'email' => 'required|string|email|max:255|unique:admins',
4)Clear the config cache or rebuild it:
php artisan config:clear
php artisan config:cache
References:
https://laracasts.com/discuss/channels/general-discussion/change-users-table-name
https://laracasts.com/discuss/channels/general-discussion/changing-users-table-name-52
Edit app/config/auth.php to change the table.
'table' => 'admin',
Source: http://laravel-recipes.com/recipes/12/changing-your-authentication-table
EDIT: That was for Laravel 4. For Laravel 5, it depends on the driver you're using. If you're using Eloquent, you can change the default model in your config/auth.php file here:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class, // Here you can change the users model
],
],
or you can specify the right table in the App\User
model.
If you're using the database driver, you can change the name of the table in the same way:
'providers' => [
'users' => [
'driver' => 'database',
'table' => 'users', // Here you can change the database table
],
],
Hope that helps.