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?
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]')
Try DB::Query('SELECT LAST_INSERT_ID()')
?
(this is DB product specific, example I've given is for MySQL/MariaDB.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With