【发布时间】:2014-07-03 09:38:52
【问题描述】:
当我尝试使用 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()。
更新1: 这是我的模型
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;
}
}
更新2:
我尝试将另一个模型名称和类名称写为Users,效果很好。但是为了认证,肯定是User表吧?
【问题讨论】:
-
您能否将您的用户型号代码添加到问题中..
-
除了默认文件中的表名外,我没有改变太多。我会更新的。
-
你可以试试 $user = new User; ...(不带函数括号)
-
我认为还有一些其他默认功能可以覆盖此模型。有没有办法调试那个东西?这是 laravel 的全新安装,这是我唯一的功能。所以这不是我的错。
-
尝试扩展 \Eloquent ...看起来 Eloquent 没有扩展......