I have a problem with replicating one of my models with all the relationships.
The database structure is as follows:
Table1: products
id
name
Table2
This worked fine on 5.5. image , media is a relation name.
$event = Events::with('image','media')->find($event_id);
if($event){
$newevent = $event->replicate();
$newevent->push();
foreach ($newevent->getRelations() as $relation => $entries)
{
foreach($entries as $entry)
{
$e = $entry->replicate();
if ($e->push())
{
$newevent->{$relation}()->save($e);
}
}
}
}