You can try insert
Check the documentation here: https://laravel.com/api/8.x/Illuminate/Database/Query/Builder.html#method_insert
Example
SubmissionFigure::insert(
[
$figdata1,
$figdata2
]
);
i have a tables like below,
id, uuid, abstract, status, user_id
id, submission_id,figure_name,figure_title
So here the relatisonip is,
public function figures()
{
return $this->hasMany('App\Models\SubmissionFigure','submission_id','id');
}
One submission may have many figures lets say single submission has 100 figures.
Now what i am doing is there is a revision process. at first submission will be empty for a user. first he enters all the details and upload all the figures and data will be inserted to submission and figures tables and status for that submission will be set as Active.
Now admin verifies the submission and enable the resubmit article button if it needs correction and admin will give option to edit the previous submission and i want to keep track of every changes. so once user clicks on resubmit submission i am using previous active submission and inserting again to same table like below,
$activearticle = ResubmitArticle::where('status','=','Active')->where('user_id',auth()->user()->id)
->first();
$newdata = [
'uuid' => unique_str('App\Models\ResubmitArticle', 'resubmit_uuid'),
'user_id' => $activearticle->user_id,
'abstract' => $activearticle->abstract,
'status' => 'Active',
];
$newinserteddata = ResubmitArticle::create($newdata);
Here previous submission status will be changed to History and newly created one will be changed to Active.
at a time only one active submission will be there which will be parent source for next edit purpose..
now i want to insert figures of $activearticle
i have tried below code,
$figuredata = $activearticle->figures;
foreach($figuredata as $data)
{
$figdata = [
'article_submission_id' => $data->article_submission_id,
'resubmit_article_id'=>$newinserteddata->id,
'figure_name' => $data->figure_name,
];
SubmissionFigure::create($figdata);
}
This is working fine but my concern is speed if the submission has more than 200 Images then i think foreach will take time to insert all the images . any other solution to achieve this?
Please or to participate in this conversation.