Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

@Jameron did you ever find a solution to this? I'm currently trying to do the same thing.

0

Ah. Found a solution. The problem with passing in null is that there is a call like this

$this->createAttachRecords((array) $id, $attributes)

Which causes $id to become an empty array when you pass in null. To get around this you can pass in [null] which will stop the conversion and will then correctly add in a row where the id is null. Using your example

$group->members()->attach(
    [null],
    array(
        'first' => $new_array[$key][0],
        'last' => $new_array[$key][1],
        'favorite_food' => $new_array[$key][2]
    )
);
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Jameron jameron Joined 16 Apr 2014

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.