phplaravellast-insert-id

laravel raw queries last_insert_id


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?


Solution

  • 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' => 'example@gmail.com')