Php Laravel-登录sql错误
当我尝试登录Laravel 5.4时,在登录页面输入电子邮件和密码后,我出现以下错误Php Laravel-登录sql错误,php,mysql,laravel,Php,Mysql,Laravel,当我尝试登录Laravel 5.4时,在登录页面输入电子邮件和密码后,我出现以下错误 SQLSTATE[42S22]: Column not found: 1054 Champ 'id' inconnu dans where clause (SQL: select * from `acteur` where `id` = 21 limit 1) 它不是正确的id名称它应该是id\u biodic\u acteur而不是id acteur是我的用户表 这是我的登录页面: <head>
SQLSTATE[42S22]: Column not found: 1054 Champ 'id' inconnu dans where clause (SQL: select * from `acteur` where `id` = 21 limit 1)
它不是正确的id名称它应该是id\u biodic\u acteur
而不是id
acteur
是我的用户表
这是我的登录页面:
<head>
<meta charset="utf-8">
<title>Se connecter</title>
<link href="/css/app.css" rel="stylesheet">
</head>
<body class="login">
<img class="logo-img" src="/img/logo.jpg" alt="">
<h1 class="title">LPO Extranet</h1>
<form class="form-login" role="form" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-input-login{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="">E-Mail</label>
<input id="email" type="email" class="form-email" name="email" value="{{ old('email') }}" required autofocus>
@if ($errors->has('email'))
<span class="">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<div class="form-input-pwd{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="">Mot de passe</label>
<input id="password" type="password" class="form-pwd" name="password" required>
@if ($errors->has('password'))
<span class="">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
<button type="submit" class="form-input-submit">
Valider
</button>
<a class="" href="{{ route('password.request') }}">
Mot de passe oublié ?
</a>
</form>
</body>
我的授权路径:
public function auth()
{
// Authentication Routes...
$this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
$this->post('login', 'Auth\LoginController@login');
$this->post('logout', 'Auth\LoginController@logout')->name('logout');
// Registration Routes...
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');
// Password Reset Routes...
$this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
$this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
$this->post('password/reset', 'Auth\ResetPasswordController@reset');
}
下面是Authentificates用户:
namespace Illuminate\Foundation\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
trait AuthenticatesUsers
{
use RedirectsUsers, ThrottlesLogins;
public function showLoginForm()
{
return view('auth.login');
}
public function login(Request $request)
{
$this->validateLogin($request);
if ($this->hasTooManyLoginAttempts($request)) {
$this->fireLockoutEvent($request);
return $this->sendLockoutResponse($request);
}
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request);
}
$this->incrementLoginAttempts($request);
return $this->sendFailedLoginResponse($request);
}
protected function validateLogin(Request $request)
{
$this->validate($request, [
$this->username() => 'required|string',
'password' => 'required|string',
]);
}
protected function attemptLogin(Request $request)
{
return $this->guard()->attempt(
$this->credentials($request), $request->has('remember')
);
}
protected function credentials(Request $request)
{
return $request->only($this->username(), 'password');
}
protected function sendLoginResponse(Request $request)
{
$request->session()->regenerate();
$this->clearLoginAttempts($request);
return $this->authenticated($request, $this->guard()->user())
?: redirect()->intended($this->redirectPath());
}
protected function authenticated(Request $request, $user)
{
//
}
protected function sendFailedLoginResponse(Request $request)
{
$errors = [$this->username() => trans('auth.failed')];
if ($request->expectsJson()) {
return response()->json($errors, 422);
}
return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors($errors);
}
public function username()
{
return 'email';
}
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->flush();
$request->session()->regenerate();
return redirect('/');
}
protected function guard()
{
return Auth::guard();
}
}
谢谢你的帮助 如果使用内置身份验证功能,则无需指定自定义的
login()方法,只需执行以下操作:
php artisan make:auth
并遵循规则
illighte\Foundation\Auth\AuthenticatesUsers
trait包含您需要的所有方法。要处理登录POST请求,您需要使用内置的postLogin()
方法
只需更改邮寄路线:
$this->post('login', 'Auth\LoginController@postLogin');
查看中的所有可用方法。将您的迁移粘贴到用户表中。尝试放置受保护的$primaryKey=“id\u biodiv\u acteur”代码>&受保护的$table=“acteur”您的App/User
Model$表中的code>和$primaryKey已在我的用户模型中。我没有迁移我的表,我是通过phpMyAdmin创建的,你为什么要这样做?Laravel包含用于数据库迁移的功能。无论如何,它正在寻找一个不存在的ID列。登录路径是否指向正确的控制器?因为我使用sql workbench创建了表,并在phpmyadmin中导入它。哦是的,它不是id的正确名称,它是“id\u biodiv\u acteur”而不是“id”,我可以在哪里更改它?谢谢,但所有都是通过这个命令生成的,我只是自定义了HTMLN,然后尝试摆脱控制器中的login()
函数,它将覆盖illumb\Foundation\Auth\AuthenticatesUsers
中的默认方法。此外,请检查身份验证路由指向的位置:php artisan路由:list
并查找URI:Auth/login;它将告诉您它试图使用的方法。因此,可以肯定的是,您建议我删除LoginController.php中的login()?我的错,它可以工作(需要清理缓存)。非常感谢。
$this->post('login', 'Auth\LoginController@postLogin');