How to Execute MySQL Query in 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.
class PostController extends Controller
* Write code on Method
* @return response()
public function index(Request $request)
INSERT INTO `posts` (`id`, `title`, `body`, `created_at`, `updated_at`, `slug`) VALUES (NULL, 'Demo Title', 'This is body', '2023-04-26 09:34:51', '2023-04-26 09:34:51', 'demo-body');
We are Recommending you
- Laravel Case Sensitive Query Search Example
- Laravel Eloquent take() and skip() Query Example
- Laravel Eloquent whereNotNull() Query Example
- Laravel Eloquent whereBetween() Query Example
- Laravel Eloquent selectRaw() Query Example
- Laravel Eloquent Order By Query Example
- Laravel Eloquent Where Query Examples
- How to Create and Use Query Scope in Laravel Eloquent
- How to use Union Query with Laravel Eloquent?
- Example of unionAll in Query Builder Laravel
- Laravel Join with Subquery in Query Builder Example
- How to add LIKE query in Elasticsearch?
- How to Get Query Log in Laravel Eloquent?