【发布时间】:2018-04-05 14:14:30
【问题描述】:
我正在使用自动生成的身份验证设置来登录和注册等。我已经让注册器正常工作,但无法让登录正常工作。
默认情况下,当我运行它时,我会收到此错误
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'email' in 'where clause' (SQL: select * from `consumers` where `email` = jermayne21@gmail.com limit 1)
这可以理解,我的数据库中的电子邮件列是con_email,我的密码列是con_password
我更新了我的LoginController.php 以将email 和password 属性更改为上述列。
LoginController.php
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use App\User;
class LoginController extends Controller
{
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* @var string
*/
protected $redirectTo = '/home';
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function username()
{
return 'con_email';
}
public function getAuthPassword()
{
return $this->con_password;
}
}
User.php(供参考)
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
protected $table = 'consumers';
protected $primaryKey = 'con_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [ 'con_id', 'con_fname', 'con_lname', 'con_email', 'con_password', 'total_earned'];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'con_password', 'remember_token',
];
}
login.blade.php(我认为我不需要更改,如果我错了请纠正我)
@extends('layouts.app')
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Login</div>
<div class="panel-body">
<form class="form-horizontal" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
从默认代码进行更改后,我不再收到错误消息。当我登录时它只是重新加载到登录屏幕而没有任何验证错误(但似乎它几乎是一个错误的信息但它不是错误的登录信息。
关于我发现的类似问题的其他答案的问题
我没有AuthController.php,但我已经阅读了许多答案,表明在该文件中覆盖它。当我运行php artisan make:auth 时,它会自动生成LoginController.php、ForgotPasswordController.php、RegisterController.php 和ResetPasswordController.php 这是laravel 5.5 中的最新更新(或者可能是根据我阅读的内容在5.2 中完成的)。我在所有控制器中都遇到了相同的当前错误,所以我想AuthController.php 可能已更改为上面的 4 个单独的控制器。
【问题讨论】:
标签: php rest laravel-5 oauth controller