The error SQLSTATE[42S22]: Column not found: 1054 Unknown column 'user_email' in 'where clause' is a classic symptom of a mismatch between your authentication configuration and your database schema. In this specific case, the root cause lies in how Laravel's Eloquent authentication driver resolves user records versus how your Member model defines its relationship to the User table.
When you configure Laravel to use the Member model for authentication (as seen in your auth.php file), the framework attempts to find a user by querying the members table directly. The error log reveals the specific failing query:
select * from members where user_email = ? limit 1
Laravel is looking for a column named user_email inside the members table because that is what your controller passes to the validator and then to Auth::attempt(). However, examining your schema shows that user_email exists only in the users table. The members table contains a foreign key user_id, but it lacks the email column itself.
This discrepancy stems from a fundamental misunderstanding of how Eloquent authentication works with composite relationships or split tables. Your Member model implements UserInterface and defines a users() relationship returning a hasOne('User'). While this establishes a logical link, Laravel's default Eloquent auth driver does not automatically traverse that relationship to find the email address when performing the initial lookup.
To resolve this, you must align your data access pattern with the database structure. Since the Member table holds the password hash and token but relies on the User table for identity details like the email, the authentication logic needs to be explicit about where that data lives.
The most robust solution is to modify the login flow in your controller to bypass the default Auth::attempt() magic method, which assumes the authentication table contains all necessary fields. Instead, you should query the User model directly using the email provided in the request, then verify the password against the associated Member.
Here is how you can refactor the store method in your controller to handle this split-schema scenario correctly:
use Illuminate\Support\Facades\Auth;
use App\User; // Assuming your User model is in the App namespace
use App\Member;
public function store()
{
$input = Input::all();
$rules = array('user_email' => 'required', 'member_password' => 'required');
$v = Validator::make($input, $rules);
if ($v->passes()) {
// 1. Query the User table for the email
$user = User::where('user_email', $input['user_email'])->first();
if ($user) {
// 2. Load the associated Member record to verify credentials
$member = Member::find($user->user_id);
if ($member && Hash::check($input['member_password'], $member->member_password)) {
Auth::login($member, true);
return Redirect::to('/home');
}
}
// Fallback to standard attempt structure or return error view
return Redirect::to('login')->withErrors($v);
} else {
return Redirect::to('login')->withErrors($v);
}
}
By explicitly fetching the User record first, you ensure that the email validation happens in the correct table. Once the User is identified, you retrieve the corresponding Member to validate the password hash. This approach respects the foreign key constraint defined in your schema (fk_members_users1) without requiring a structural change to your database, which might impact existing data or application logic.
Alternatively, if you prefer to keep using Auth::attempt(), you would need to modify the Member model to override the default authentication behavior, perhaps by changing how the provider resolves the user. However, given that Laravel 5.x (implied by the use of Input::all() and older Eloquent syntax) does not support querying across relationships for auth out of the box, the manual lookup pattern is safer and more predictable.
If you are maintaining a legacy application where this split-table design was chosen intentionally, ensure that your migration files accurately reflect the current state of the database. For instance, your Migration Member file references Schema::table('members'), but the actual column names in the SQL dump use backticks (e.g., `member_password`). While Laravel's Schema Builder is generally forgiving with naming conventions, ensuring consistency between migration definitions and actual DB definitions prevents subtle bugs during future migrations.
Finally, if you are looking for a more modern approach to handling authentication in Laravel without splitting user and member data into separate tables, consider reviewing the official documentation on setting up custom auth providers or upgrading to a version where relationship-based authentication is better supported. For further reading on securing your authentication flow, resources like https://laravelcompany.com can provide deeper insights into implementing secure login strategies in complex architectures.