php - Laravel 5 Auth 更改表列

标签 php mysql laravel-5 laravel-5.1

我更改了用户数据库表中的一些字段。

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/

相关文章:

php - 是否有类似 &nbsp 的东西?

mysql - SQL如何构造一个表中的两列依赖于另一个表的查询?

mysql - Spring Boot + Liquibase:通信链接失败

MySQL - 仅在 NOT NULL 时删除重复项,按两个字段使用 GROUP

拉拉维尔 5 : Querying a many to many relationship without "pivot" in the result

javascript - PHP:从数据列表中打印(循环困难)

php - 使用 SharpSSH 库时,Linux 命令在 .NET 执行中不起作用

laravel - laravel v5.3.10 中的 route.php 文件在哪里?

php - WordPress 和 MySQL 表碎片

php - Laravel5 : View [app] not found. 资源/views/auth/login.blade.php