Can't seed created_by column while seeding table
Created 7 years ago by lckamal

What should we do to seed created_by column? My seeder looks like this:

$this->teams->create(
                [
                    'created_by'      => UserModel::find(3),
                    'name'            => $faker->company,
                    'no_players'     => $faker->numberBetween(1,12),
                    'image' => FolderModel::where('slug', 'team')->first()->files()->inRandomOrder()->first()->id
                ]
            );

I have also tried

'created_by' => 3
Both option didn't work.
dali  —  7 years ago Best Answer

did you try getting the created entry and modify it afterwards?

$entry = $this->teams->create(.....

$entry->setAttribute('created_by',3)->save();
lckamal  —  7 years ago

it worked. Thanks a lot. I think you can help on truncating pivot related table data when truncating data from main table.

$this->teams->truncate();

This will truncate teams table data. But I see teams_members data are still there. Is there any quick method for this?

ryanthompson  —  7 years ago

Open an issue if you would this is being aggressively overrides it would seem.