Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

Insert doesn't return anything but a success boolean, so I think your only option is to query your table before the insert to find the max id, then count your $data array with count(), and determine the to-be ids with that.

There might be a more semantic way to do this...but I think this will work (untested).

$data = array(
    array('name'=>'Bar', 'lastname'=>'Baz'),
    array('name'=>'Foo', 'lastname'=>'Baz'),
);

$max_id = DB::table('users')->max('id');
$ids = array();
foreach ($data as $i => $row) /* assuming non-associative keys, and that at least one record already exists */
{
    $ids[] = $max_id + $i + 1;
}

YourModel::insert($data);
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kyoukhana kyoukhana Joined 28 Feb 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.