我想使用列电子邮件和密码进行登录。
注册期间对密码进行哈希处理,然后将其保存到数据库('driver' => 'database')。
电子邮件列不是主键,而是唯一的。

AuthController.php:

// Get all the inputs
        $userdata = array(
            'email' => Input::get('username'),
            'password'  => Input::get('password')
        );

        // Declare the rules for the form validation.
        $rules = array(
            'email' => 'Required',
            'password'  => 'Required'
        );

        // Validate the inputs.
        $validator = Validator::make($userdata, $rules);

        // Check if the form validates with success.
        if ($validator->passes())
        {

            // Try to log the user in.
            if (Auth::attempt($userdata, true))
            {
                // Redirect to homepage
                return Redirect::to('')->with('success', 'You have logged in successfully');
            }
            else
            {
                // Redirect to the login page.
                return Redirect::to('login')->withErrors(array('password' => 'password invalid'))->withInput(Input::except('password'));
            }
        }


无论如何,我只是报错:
ErrorException
未定义索引:ID

它还向我显示了这一点:

 public function getAuthIdentifier()
        {
            return $this->attributes['id'];
        }


我做错了什么?谢谢

编辑

用户模型:

<?php

use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password');

    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->getKey();
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the e-mail address where password reminders are sent.
     *
     * @return string
     */
    public function getReminderEmail()
    {
        return $this->email;
    }
}

最佳答案

getAuthIdentifier是接口方法。 GenericUser类正在实现该方法,并且需要用户ID。

因此,检查您的模型上是否确实具有id属性。

关于php - Laravel try()不起作用,getAuthIdentifier使用错误的列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22128931/

10-11 02:50