How do I get the array data inside Input :: all () and store it as a hasMany () relation to the actual record?
I am working on a project and there is a table diagnostics. There is another diagnost_detail table. Diagnostics has a one-to-large relationship with diagnostic_detex. The post data sent to the diagnostics controller to create a new record contains all information about the diagnostics itself and an array of data that must be entered into the diagnost_detail method.
Now it's easy to create a diagnostic entry:
Diagnostic::create(Input::all());
But how can I take all the data for the parts and create it?
source to share
You will need to create a cycle and create a part object manually. Try the following:
$details = array();
foreach(Input::get('diagnostic_detail') as $detail){
$details[] = new DiagnosticDetail($detail);
}
$diagnostic->details()->saveMany($details);
In this example DiagnosticDetail
, this is the referenced model hasMany()
and the details
hasMany relationship.
More information on inserting linked models
source to share