How to Execute mysql Query in Laravel?

By Hardik Savani September 6, 2020 Category : Laravel

Sometimes, we require to run directly mysql query on Laravel for example if you need to copy one table to other table using mysql query. I also need in one project and that's why i am fetching problem. But you can use sql query on laravel using db statement in bellow example you can learn how to run.

Example:

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."

");

We are Recommending you