默认用户模型在laravel中抛出错误

时间:2014-05-15 05:17:54

标签: php class laravel model

默认型号"用户"在laravel中,当我尝试使用它时会抛出错误。我试过的是,

$user = new User();
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->name = "Blah Blah";
$user->access_type = "admin";
$user->access_status = 1;
$user->save();

,抛出的错误是

Symfony \ Component \ Debug \ Exception \ FatalErrorException

Call to undefined method User::save()

问题是什么?我还尝试User::all()来检索值,这也会引发错误Call to undefined method User::all()

UPDATE1: 这是我的模特

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 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->email;
    }

}

UPDATE2: 我尝试将另一个模型名称和类名称编写为Users,这非常有效。但是对于身份验证,它必须是User表吗?

3 个答案:

答案 0 :(得分:1)

问题的原因是自动加载器加载错误的“用户”模型。请查看“/vendor/composer/autoload_classmap.php”文件。在“User”键的返回数组值内必须是$baseDir . '/app/models/User.php

return array(
...,
'User' => $baseDir . '/app/models/User.php',
...,
);

答案 1 :(得分:0)

也许User是一个保留字,只需给模型另一个名字叫UserTbl

答案 2 :(得分:0)

仍未收到我的问题的任何答案。无论如何,现在我正在使用名为Users的新模型运行它,并考虑到同样的疑问。