Have you seen our video tutorials? Check 'em out!

Can't seed created_by column while seeding table

lckamal - 1 week ago

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 - 1 week ago

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

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

$entry->setAttribute('created_by',3)->save();

lckamal - 1 week 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 - 1 week ago

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