Laravel Seeding Does not Fill in Fields

江枫思渺然 提交于 2019-12-04 06:49:29

I had this same problem but none of the above solutions worked for me. It turned out to be due to having a construct function in my model! After I removed this it worked fine!

public function __construct()
{
    parent::__construct();
}

EDIT: After further reading on this I discovered the issue is due to the fact that if you are going to include a constructor in your model must accept the attributes parameter and pass it to the parent. If you do this then the constructor does not break the DB seeding (and probably other things). I hope this saves someone else a headache.

public function __construct($attributes = array())
{
    parent::__construct($attributes);
}
Gareth Daine

Turns out the issue was to do with relationships in my models.

For future visitors to this question: make sure to check all the functions in your models that define hasOne/hasMany/etc relationships. Read though the Eloquent docs for more.

Do you have $this->call("ContactTableSeeder") in your DatabaseSeeder class' run() function?

If you have ContactTableSeeder in it's own file, is the file named ContactTableSeeder.php exactly? If not it would fail to load according to the PSR-0 Standard.

These are my first thoughts.

vlad

Have you tried to replace the following lines:

foreach ($contacts as $contact) {
   Contact::create($contact);
}

with

DB::table('contact')->insert($contacts);

assuming your table name is contact. And also, make sure you have line like this

$this->call('ContactTableSeeder');

in your DatabaseSeeder class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!