Dri*_*ies 1 php laravel laravel-4
我正在laravel 4中申请,我遇到了一个问题.
到目前为止,我已经尝试建立一个身份验证系统.我遵循了几个教程,但似乎都没有.可能是因为教程已经过时(laravel不断发展).
这是我的情况:
我有一个登录表单,此表单对用户进行身份验证.它工作得很好,这是我的routes.php文件中的代码.
Route::post('login', function () {
$user = array(
'e-mail' => Input::get('E-mail'),
'password' => Input::get('password')
);
if (Auth::attempt($user)) {
return Redirect::route('home')
->with('flash_notice', 'You are successfully logged in.');
}
// authentication failure! lets go back to the login page
return Redirect::route('login')
->with('flash_error', 'Your username/password combination was incorrect.')
->withInput();
});
Run Code Online (Sandbox Code Playgroud)
因此,当我登录时,我转到主页并显示消息,没有问题.在我看来,我有以下代码(我使用刀片).
<ul>
<li><a href="{{ URL::to('home') }}">Home</a></li>
@if(Auth::check())
<li><a href="{{ URL::to('profile') }}">Profile</a></li>
<li><a href="{{ URL::to('logout', 'Logout ('.Auth::user()->e-mail.')') }}">Logout</a></li>
@else
<li><a href="{{ URL::to('login') }}">Login</a></li>
@endif
</ul>
Run Code Online (Sandbox Code Playgroud)
问题是无论Auth :: check()返回false是什么.我已经研究了这个问题好几个小时了,不知道在哪里继续......
在User模型中,getKey()方法返回null,所以我认为我的数据库可能是错误的.但数据正在完美呈现.
谢谢你的时间.
Dri*_*ies 15
事实证明这是一个愚蠢的错误.Laravel在小键盘中将默认主键定义为"id".我在数据库中使用的ID被定义为"ID".
我通过更改数据库中的字段名称来修复此问题.另一种选择是定义
protected $primaryKey = 'ID';
Run Code Online (Sandbox Code Playgroud)
在你的模型中......
祝你今天愉快
| 归档时间: |
|
| 查看次数: |
4868 次 |
| 最近记录: |