tiffanyhwang
tiffanyhwang

Reputation: 1453

Laravel db not seeding because a Model that extends Eloquent has a constructor...?

So I have a simple seeder that simply has User::create(array(...)) but it will not seed because my base model has a constructor:

BaseModel extends Eloquent {

protected $local_name;

public __construct()
{
  parent::__construct();
  $this->locale_name = App::getLocale();
}

And any model (e.g. User) extending the BaseModel will not seed properly when I give a string as a field. Say for example:

User::create(array('id' => 1, 'foo' => 'bar'));

The foo field will be NULL whilst the id field would turn out fine and store the integer. It happens to any string and only strings I give it.

Anyone know what's wrong? It doesn't matter what's in the constructor, the same thing will happen.

Upvotes: 0

Views: 483

Answers (1)

The Alpha
The Alpha

Reputation: 146219

The constructor must have an $attributes array set as default:

class BaseModel extends Eloquent {
    public function __construct($attributes = array())
    {
        parent::__construct($attributes);
        // your code
    }
}

Upvotes: 1

Related Questions