Now here we will see How to Execute mysql Query in Laravel? Sometimes, we need to run the directly mysql query on our Laravel application. For example if we need to copy one table data to other table by using mysql query. Sometimes we also need in one project and that’s why we are fetching that’s problem. But we can use sql query on laravel by using db statement. Now in the bellow example we can learn how to run.
DB::statement(" INSERT INTO `posts` (repost_of_id,token_id,post_details,user) SELECT id,token_id,post_details,".$loginUserId." FROM `posts` where id = ".$postId." ");
Read Also : How to convert Object into Array in PHP?
Thanks for read. I hope it help you. For more you can follow us on facebook.