lundi 2 mars 2020

Laravel replicate multiple rows didn't work

I want to replicate multiple relational rows to the same table with the diff job id. But it doesn't work.

Here is my code

$parentJobUnits = Unit::where('job_id',$jobId)->get();  //may be single or multiple rows for units.

$JobCopy = $job->replicate()->save();    //main job copied for new units.

$partsCopy = array_map(function(Unit $unit) use($JobCopy)
{

     $newUnit = $unit->replicate();
     $newUnit->job_id = $JobCopy->id;
     return $newUnit->save();

}, $parentJobUnits);

The above code is not working for multiple row replication.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire