I have a dynamic input field called name="step[]". When submitting the form and displaying the $request->step using dd, I get this:
array:3 [
0 => "Test Step 1"
1 => "Test Step 2"
2 => "Test Step 3"
]
So it is an array. Now, when I want to insert the data using:
$project = new Project;
$project->name = $request->name;
$project->save();
$project->steps()->saveMany($request->step);
I am getting this error:
Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, string given
Project Model:
public function steps()
{
return $this->hasMany('App\Step');
}
My goal is to create a new Project and save it to the database, and save all steps in my Step table. So each Project hasMany steps. Not sure why I am getting the above error though, since I am passing an array?
arrayyes. Anarrayof models, no.$project->steps()->saveMany( /** array of models expected */).