Updating multiple many to many relationships

Posted 8 months ago by bcharron

I am wondering if there is a best practice when it comes to updating the pivot table for a many to many relationship. I currently have the following code which updates each pivot table record individually, but wonder if there is a better way to do this?

foreach( $job->codes as $code ) {
    $job->codes()->updateExistingPivot(
        $code->id,
        [
            'approved' => 1
        ]
    );
}

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.