我使用的Laravel 4.2,我試圖授權我自己的模型(我不使用User
模型)。 這個問題似乎當通過郵件和密碼,然後我使用的方法Auth::attempt
和進入到其他(即它對應於錯誤)爲什麼我自己的身份驗證不能在Laravel中使用我自己的模型?
Usuario控制器
class UsuarioController extends BaseController{
function doLogin(){
$userdata = array(
'Correo' => Input::get('correo'),
'Contrasena' => Input::get('contrasena')
);
if(Auth::attempt($userdata)){
echo 'SUCCESS!';
}else{
echo 'Error!';
}
} ...
Usuario模型
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class Usuario extends Eloquent implements UserInterface, RemindableInterface {
protected $table = 'Usuario';
protected $primaryKey = 'idUsuario';
protected $fillable = array(
'Nombre',
'Apellido',
'Rol',
'Correo',
'Contarsena',
'Cumpleanos',
'Foto',
'Pais',
'Comuna',
'Profesion_idProfesion',
'Institucion_idInstitucion',
'remember_token'
);
function profesion(){
return $this->belongsTo('Profesion', 'idProfesion');
}
public function getPasswordAttribute()
{
return $this->Contrasena;
}
public function setPasswordAttribute($Contrasena)
{
$this->Contrasena= $Contrasena;
}
public function getReminderEmail()
{
return $this->Correo;
}
public function getRememberToken()
{
return $this->remember_token;
}
public function setRememberToken($value)
{
$this->remember_token = $value;
}
public function getRememberTokenName()
{
return 'remember_token';
}
public function getAuthIdentifier()
{
return $this->getKey();
}
public function getAuthPassword() {
return $this->Contrasena;
}
}
Auth.php
return array(
'driver' => 'eloquent', //database or eloquent
'model' => 'Usuario',
'table' => 'Usuario',
'username' => 'Correo',
'password' => 'Contrasena',
'reminder' => array(
'email' => 'emails.auth.reminder',
'table' => 'password_reminders',
'expire' => 60,
),
);
Usuario表
應用永不死機,但在如果條件隨時進入到'其他 '' 返回錯誤!
如果我這樣做返回''未找到列:1054未知列'電子郵件'在'where子句'(SQL:select * from'Usuario'其中'email' = [email protected]限制1)' '所以我用''Correo''替換''email'並且工作:D – cheloncio 2014-09-25 15:16:54