laravel raw queries last_insert_id

Sinan picture Sinan · Nov 9, 2012 · Viewed 10.1k times · Source

Is there a way to get the last_insert_id when using laravel's raw query?

DB::query('INSERT into table VALUES ('stuff') ')

This returns true or false. Is there a way to get last_insert_id using raw queries in Laravel?

Answer

Dele picture Dele · May 6, 2013

Just the benefit of those who might have be having the same question for laravel 4, there is a slight syntax change from @haso-keric's response.

It is:

$id = DB::table('users')->insertGetId(array('email' => '[email protected]')