默认用户模型在laravel中抛出错误 [英] Default User model throws error in laravel
问题描述
laravel中的默认模型User在我尝试使用它时抛出错误。我试过的是,
The default model "User" in laravel throws error when I tried to use it. What I tried is,
$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()
来检索值,这也抛出错误调用未定义的方法User :: all()
。
What is the issue? I also tried User::all()
to retrieve the values, which also throws error Call to undefined method User::all()
.
Update1:
这是我的模型
Update1: Here is my model
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
表右对齐?
Update2:
I tried writing another model names and class name as Users
, which works perfectly. But for authentication, it must be the User
table right?
推荐答案
仍然没有收到我的问题的任何答案。现在我使用名为用户
的新模型运行它,同样怀疑。
Still didn't received any answer to my question. Anyways now I'm running it using the new model named Users
with the same doubt in mind.
这篇关于默认用户模型在laravel中抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!