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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -