Skip to content
Advertisement

Laravel Factories and Seeding: Static array of arrays

For some of my tables, I’d like to insert a fixed amount of rows with specific data.

This is my categories factory:

JavaScript

This is the seeder:

JavaScript

I get this error: preg_match() expects parameter 2 to be string, array given

Is there a way to insert a fixed amount of static information into certain tables using seeding and factories?

Advertisement

Answer

I think you want to use Seeder with static values, if I am correct you should use

Define Category seeder

JavaScript

And in DatabaseSeeder

JavaScript

Now run php artisan db:seed and it will be done.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement