【问题标题】:Why am I getting this Laravel 4 error: "User must implement Remindable interface"为什么我会收到此 Laravel 4 错误:“用户必须实现可提醒接口”
【发布时间】:2013-10-08 08:36:09
【问题描述】:

我正在尝试使用 MySQL 实现用户身份验证(重置电子邮件功能),但我一直收到此错误 User must implement Remindable interface.,我知道 User 正在实现 RemindableInterface,因为我使用的是 Laravel 附带的身份验证系统4.

并且在数据库配置文件中输入了正确的数据库凭据。任何帮助将不胜感激。谢谢。

代码如下:

config/auth.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' => 'database',

  /*
  |--------------------------------------------------------------------------
  | 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.
  |
  | The "expire" time is the number of minutes that the reminder should be
  | considered valid. This security feature keeps tokens short-lived so
  | they have less time to be guessed. You may change this as needed.
  |
  */

  'reminder' => array(

    'email' => 'emails.auth.reminder',

    'table' => 'password_reminders',

    'expire' => 60

  )

);

models/User.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;
  }

}

【问题讨论】:

  • 您尝试过'driver' => 'database','driver' => 'eloquent', 上的config/auth.php 吗? (您正在扩展Eloquent)或者可能将protected $key = 'userid';protected $primaryKey = 'userid'; 添加到model/User.php
  • 感谢您的回复,我会尝试您的建议。我使用的是 MySQL 而不是 Eloquent 并且我看到的所有示例都扩展了 eloquent 所以我不知道如果不是 User.php 上的 Eloquent 应该扩展哪个类
  • 我尝试了你的建议,但仍然没有。我要实现的是密码重置功能。

标签: php mysql laravel laravel-4


【解决方案1】:

如果您使用'driver' => 'database',则无需指定任何模型,因为Auth 将直接使用查询生成器处理表。我推荐你使用eloquent,因为通过模型你可以获得更多的功能,比如提醒、关系访问等。

【讨论】:

  • 好吧,我想我对 eloquent 与数据库驱动程序的理解有误。它现在可以工作了,谢谢您的回答。我真的很感激。
猜你喜欢
  • 2018-06-22
  • 2016-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-04
  • 1970-01-01
相关资源
最近更新 更多