36

I'm using the framework Laravel.

I have 2 tables (Users and Members). When I want to login, I get the error message:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_email' in 'where clause' (SQL: select * from members where user_email = ? limit 1) (Bindings: array ( 0 => '[email protected]', ))

Table Users

CREATE TABLE IF NOT EXISTS `festival_aid`.`users` ( `user_id` BIGINT NOT NULL AUTO_INCREMENT, `user_email` VARCHAR(45) NOT NULL, `user_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `user_modified` TIMESTAMP NULL, `user_deleted` TIMESTAMP NULL, `user_lastlogin` TIMESTAMP NULL, `user_locked` TIMESTAMP NULL, PRIMARY KEY (`user_id`), UNIQUE INDEX `user_email_UNIQUE` (`user_email` ASC), ENGINE = InnoDB; 

Table Members

CREATE TABLE IF NOT EXISTS `festival_aid`.`members` ( `member_id` BIGINT NOT NULL AUTO_INCREMENT, `member_password` CHAR(32) NOT NULL, `member_salt` CHAR(22) NOT NULL, `member_token` VARCHAR(128) NULL, `member_confirmed` TIMESTAMP NULL, `user_id` BIGINT NOT NULL, PRIMARY KEY (`member_id`, `user_id`), INDEX `fk_members_users1_idx` (`user_id` ASC), CONSTRAINT `fk_members_users1` FOREIGN KEY (`user_id`) REFERENCES `festival_aid`.`users` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB; 

Migration User

public function up() { Schema::table('users', function(Blueprint $table) { $table->increments('user_id'); $table->string('user_email'); $table->timestamp('user_created'); $table->timestamp('user_modified'); $table->timestamp('user_deleted'); $table->timestamp('user_lastlogin'); $table->timestamp('user_locked'); }); } 

Migration Member

public function up() { Schema::table('members', function(Blueprint $table) { $table->increments('member_id'); $table->string('member_password'); $table->string('member_salt'); $table->string('member_token'); $table->foreign('user_id') ->references('id')->on('users'); //->onDelete('cascade'); $table->timestamp('member_confirmed'); }); } 

Model User

class User extends Eloquent { protected $table = 'users'; /** * The primary key for the model. * * @var string */ protected $primaryKey = 'user_id'; public $timestamps = false; } 

Model Member

use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableInterface; class Member extends Eloquent implements UserInterface, RemindableInterface { protected $table = 'members'; /** * The attributes excluded from the model's JSON form. * * @var array */ protected $hidden = array('member_password'); /** * Get the unique identifier for the user. * * @return mixed */ public function getAuthIdentifier() { return $this->getKey(); } /** * Get the password for the user. * * @return string */ public function getAuthPassword() { return $this->member_password; } /** * Get the e-mail address where password reminders are sent. * * @return string */ public function getReminderEmail() { return $this->email; } /** * The primary key for the model. * * @var string */ protected $primaryKey = 'member_id'; public $timestamps = false; public function users() { return $this->hasOne('User'); } } 

The Member model uses: use Illuminate\Auth\UserInterface;

<?php namespace Illuminate\Auth; interface UserInterface { /** * Get the unique identifier for the user. * * @return mixed */ public function getAuthIdentifier(); /** * Get the password for the user. * * @return string */ public function getAuthPassword(); } 

Controller

public function store() { $input = Input::all(); $rules = array('user_email' => 'required', 'member_password' => 'required'); $v = Validator::make($input, $rules); if($v->passes()) { $credentials = array('user_email' => $input['user_email'], 'member_password' => $input['member_password']); if(Auth::attempt($credentials)) { return Redirect::to('/home'); } else { return Redirect::to('login'); } } else { return Redirect::to('login')->withErrors($v); } } 

auth.php

return array( /* |-------------------------------------------------------------------------- | Default Authentication Driver |-------------------------------------------------------------------------- | | This option controls the authentication driver that will be utilized. | This drivers manages the retrieval and authentication of the users | attempting to get access to protected areas of your application. | | Supported: "database", "eloquent" | */ 'driver' => 'eloquent', /* |-------------------------------------------------------------------------- | Authentication Model |-------------------------------------------------------------------------- | | When using the "Eloquent" authentication driver, we need to know which | Eloquent model should be used to retrieve your users. Of course, it | is often just the "User" model but you may use whatever you like. | */ 'model' => 'Member', /* |-------------------------------------------------------------------------- | Authentication Table |-------------------------------------------------------------------------- | | When using the "Database" authentication driver, we need to know which | table should be used to retrieve your users. We have chosen a basic | default value but you may easily change it to any table you like. | */ 'table' => 'members', /* |-------------------------------------------------------------------------- | Password Reminder Settings |-------------------------------------------------------------------------- | | Here you may set the settings for password reminders, including a view | that should be used as your password reminder e-mail. You will also | be able to set the name of the table that holds the reset tokens. | | The "expire" time is the number of minutes that the reminder should be | considered valid. This security feature keeps tokens short-lived so | they have less time to be guessed. You may change this as needed. | */ 'reminder' => array( 'email' => 'emails.auth.reminder', 'table' => 'password_reminders', 'expire' => 60, ), ); 

What am I doing wrong here?

4
  • Where's the code relating to Auth::attempt($credentials)? Commented Dec 20, 2013 at 20:20
  • Isn't that the code in my Model: Member? Commented Dec 20, 2013 at 20:22
  • I'm not familiar with the framework, but Auth::attempt is a static call to the attempt method of the Auth class, not to Member::something Commented Dec 20, 2013 at 20:24
  • The Member model uses this: use Illuminate\Auth\UserInterface; Commented Dec 20, 2013 at 20:37

5 Answers 5

36

You have configured the auth.php and used members table for authentication but there is no user_email field in the members table so, Laravel says

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_email' in 'where clause' (SQL: select * from members where user_email = ? limit 1) (Bindings: array ( 0 => '[email protected]', ))

Because, it tries to match the user_email in the members table and it's not there. According to your auth configuration, laravel is using members table for authentication not users table.

Sign up to request clarification or add additional context in comments.

5 Comments

That's the point ,, you have to look for your validation ( exists[table] ) , you have to be sure that the table which you validate against have the row matched.
what is mean :-> SQLSTATE[42S22]: Column not found: 1054 Unknown column '''' in where clause, and where class is :-> WHERE (' ' = ''''), can i get help @The Alpha
In that table the mentioned column is not available. @Gem
Actually i get this error from soap API, how can I update in soap.
Someone already post in Magento forum, community.magento.com/t5/Magento-1-x-Programming/…
4

You don't have a field named user_email in the members table ... as for why, I'm not sure as the code "looks" like it should try to join on different fields

Does the Auth::attempt method perform a join of the schema? Run grep -Rl 'class Auth' /path/to/framework and find where the attempt method is and what it does.

3 Comments

The user_email field is located in the users table. The Auth::attempt only redirects you to the homepage or back to loginpage.
No, that is the action that has been specified as a result of a successful (read returns true) call to Auth::attempt. You need to find the code that contains 'class Auth '
class Auth doesn't exist beyond being a Facade to Laravel's IoC container that has bindings to Authorization methods. Auth::attempt uses laravels configuration / extensions (via closures) to build the Auth implementation. Not havinng a user_email field in the members table however is spot on. :)
1

I was also this Problem in laravel version 9 when I created multi-authentication.

I use the Same Table as the User like this:

 $table->id(); $table->string('name'); $table->string('email')->unique(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->softDeletes(); $table->timestamps(); 

and my problem is Solved :)

Comments

0

Try to change where Member class

public function users() { return $this->hasOne('User'); } return $this->belongsTo('User'); 

1 Comment

This is fixed mine, while I have the same error but confused between belongsTo and hasMany, thanks.
-2

Just use this command:

php artisan migrate:refresh --seed 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.