【发布时间】:2013-05-30 18:51:49
【问题描述】:
我很难使用 Laravel 4 Auth::attempt 方法,遵循正确的文档,阅读了几个 SO 线程,但我仍然无法让它工作。
$userData = array('email' => 'admin@admin.com','password' => 'admin');
if(Auth::attempt($userData)){
// redirect
}
else{
echo 'Invalid';
}
而且每次都返回 Invalid
现在我不确定真正的原因是什么。
在我的 config/auth.php 我有以下内容
<?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' => 'User',
/*
|--------------------------------------------------------------------------
| 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' => 'users',
/*
|--------------------------------------------------------------------------
| 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.
|
*/
'reminder' => array(
'email' => 'emails.auth.reminder', 'table' => 'password_reminders',
),
);
?>
【问题讨论】:
-
我已经告诉了你问题的答案,你想要的就投反对票吧。您的数组键错误,您的登录将一直失败。玩得开心。
-
你不应该担心否决票,你认为如果尝试了几种组合,那么电子邮件或用户名至少在 laravel4 中不是必需的选项,laravel.com/docs/security。阅读此文档以获得更好的理解......
-
我认为您的意思是链接到Laravel 4's documentation. 我现在遇到了类似的问题。一旦我弄清楚了,我会尝试在这里发布。
标签: php authentication laravel laravel-4