php - Laravel 5.1: get insert ids for each record inserted -
my application needs custom tagging system. means creating multiple records each new tag, , adding id's of records pivot table.
i can insert multiple records array using laravels "insert":
$tag_titles = explode(",", $tag_titles); foreach ($tag_titles $tag_title) { $tags[] = array('tag_title' => $tag_title); } $tag = tag::insert( $tags );
but need know id's created during insert. there way of doing without making multiple calls db each insert separately?
thanks.
so far have tried
sync() method work single id :
$tag->content()->sync($tags);
after insert, $tag not object, $tag->id won't work
it looks you're using querybuilder instance insert, in case, should able use insertgetid
https://laravel.com/api/5.1/illuminate/database/query/builder.html#method_insertgetid
Comments
Post a Comment