我更改了用户数据库表中的一些字段。
table name: users
primaryKey: user_id
username: user_username
password: user_password
e-mail: user_mail
在 Illuminate\Foundation\AuthAuthenticatesUsers 中我添加了 protected $username = 'user_username'
;
当我尝试登录我的帐户时,我在输入用户名和密码后看到一个空白页面。调试已开启但无法正常工作。发生了什么事?
Auth::attempt(array(
'user_username' => 'pionas',
'user_password' => '12345',
));
在 User
模型中,我添加了 getAuthPassword
并将列名称更改为 user_password
。日志清晰。
Auth::loginUsingId(1);
- 不工作
可能 Auth 中的所有方法都不起作用。
我的用户模型是:
<?php
namespace App\User;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
protected $primaryKey = 'user_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['user_username', 'user_mail', 'user_password', 'user_group_id', 'user_code', 'user_rang'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('user_password', 'remember_token');
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->user_password;
}
public function comment()
{
return $this->hasOne('UserField', 'user_id');
}
/**
最佳答案
您似乎已经删除了 Laravel 5.1 使用的一些必需特征。这是一个更新后的用户模型,其中恢复了这些特征:
<?php
namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract,
AuthorizableContract,
CanResetPasswordContract
{
use Authenticatable, Authorizable, CanResetPassword;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
protected $primaryKey = 'user_id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['user_username', 'user_mail', 'user_password', 'user_group_id', 'user_code', 'user_rang'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('user_password', 'remember_token');
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->getKey();
}
/**
* Get the token value for the "remember me" session.
*
* @return string
*/
public function getRememberToken()
{
return $this->remember_token;
}
/**
* Set the token value for the "remember me" session.
*
* @param string $value
* @return void
*/
public function setRememberToken($value)
{
$this->remember_token = $value;
}
/**
* Get the column name for the "remember me" token.
*
* @return string
*/
public function getRememberTokenName()
{
return 'remember_token';
}
/**
* Get the e-mail address where password reminders are sent.
*
* @return string
*/
public function getReminderEmail()
{
return $this->user_mail;
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->user_password;
}
public function comment()
{
return $this->hasOne('UserField', 'user_id');
}
/**
* Scope a query to only include users of a given type.
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeOfStatus($query, $type)
{
return $query->where('user_status', $type);
}
}
关于php - Laravel 5 Auth 更改表列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32339910/