1

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();

and the error thrown is

Symfony \ Component \ Debug \ Exception \ FatalErrorException

Call to undefined method User::save()

What is the issue? I also tried User::all() to retrieve the values, which also throws error Call to undefined method User::all().

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: I tried writing another model names and class name as Users, which works perfectly. But for authentication, it must be the User table right?

13
  • Can you please add your User model code to the question.. Commented May 15, 2014 at 5:25
  • I have't changed anything much other than the table name in default file. I'll update it. Commented May 15, 2014 at 5:26
  • Can you try $user = new User; ... (without function brackets) Commented May 15, 2014 at 5:34
  • I think there is some other default function which overrides this model. Is there any way to debug that thing? It's a fresh installation of laravel and this is my only function. So it's not my mistake. Commented May 15, 2014 at 5:37
  • Try extends \Eloquent ...Looks like Eloquent is not extended.. Commented May 15, 2014 at 5:37

3 Answers 3

1

The reason for the issue is autoloader load wrong "User" model. Please have a look at the "/vendor/composer/autoload_classmap.php" file. Inside the return array value for the key "User" must be $baseDir . '/app/models/User.php

return array(
...,
'User' => $baseDir . '/app/models/User.php',
...,
);
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe User is a reserved word, just give the model another name say UserTbl

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.