Support the ongoing development of →
Last updated 1 month ago.

I don't think there's an existing sync function but it wouldn't be too terribly difficult to create one, probably a worthy addition to a hasMany relation.

However, you could simplify your code as-is using something like this...

$audiochannel_ids = array();
foreach ($video->audiochannels as $key => $audiochannel)
    $audiochannel_ids[] = $audiochannel->id;

AudioChannels::where('video_id', $video->id)->whereNotIn('id', $audiochannel_ids)->delete();
Last updated 1 month ago.

Looking for the same. BUT, instead of storing new records, and afterwards erasing those which are not new, I would prefer to erase all relevant data, and then store new records.

Last updated 1 month ago.

What about:

    $video->audiochannels()->saveMany(// array of audiochannels);

Hope this helps

Last updated 1 month ago.

Sign in to participate in this thread!


Your banner here too?

thedamon thedamon thedamon Joined 2 Feb 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 - All rights reserved.