How to Execute mysql Query in Laravel?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

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.

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

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.

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →