Good day, until now I have been seeding static data into my DB using the following code on my seeders:
public function run(){
$farms = array(
"N/A",
"Farm 1",
"Farm 2",
"Farm 3"
);
foreach ($farms as $farm){
Farm::create([
'name' => $farm
]);
}
}
And it has been working perfectly, but now I'm trying to use the same code to seed multiple static data in a new table (using a different seeder):
public function run()
{
$varieties = array(
"Plant 1",
"Plant 2",
"Plant 3"
);
$farms = array(
"1",
"2",
"3"
);
$crops = array(
"2019",
"2020",
"2021"
);
foreach ($varieties as $variety){
Plant::create([
'variety' => $variety,
'farm_id' => $farms,
'crop' => $crops
]);
}
}
But now Im getting the error:
Array to string conversion
Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap{closure}("Array to string conversion"
Illuminate\Support\Str::replaceArray("?", "insert into [plants] ([variety], [farm_id], [crop], [updated_at], [created_at]) values (?, ?, ?, ?)")
Any help will be appretiated.