I am new in laravel and trying to get last inserted id from this query:
DB::select("INSERT INTO current_survey (`name`, `created_by`, `description`) SELECT `name`, `created_by`, `description` FROM survey WHERE id=survey_id");
this query working well, can any one suggest me how this is possible in laravel?
Thanks
The LAST_INSERT_ID() function returns the AUTO_INCREMENT id of the last row that has been inserted or updated in a table.
Insert(): This function is simply used to insert a record into the database. It not necessary that ID should be autoincremented. InsertGetId(): This function also inserts a record into the table, but it is used when the ID field is auto-increment.
Try it once :-
$id = DB::getPdo()->lastInsertId();
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