Today, We want to share with you Laravel 6 Execute MYSQL query – Raw Queries in Laravel.In this post we will show you wordpress plugin require another plugin, hear for how to run sql query in laravel 5, 5.8, 6 we will give you demo and example for implement.In this post, we will learn about simple select query in laravel with an example.
Laravel 6 Execute MYSQL query – Raw Queries in Laravel
There are the Following The simple About How to execute raw queries with Laravel 6? Full Information With Example and source code.
As I will cover this Post with live Working example to develop laravel database transactions with eloquent, so the laravel raw query with parameters is used for this example is following below.
How to execute MYSQL query in laravel 6?
Example 1: using DB Object
$sqlQuery = "SELECT d1.update_id FROM..."; $result = DB::select(DB::raw($sqlQuery));
Example 2: simple select query in laravel 6
$products = DB::select("SELECT products.id_product, products.hash_product, products.`table`, visitors.name, 0 as total, cards.card_status, products.created_at as last_update FROM products LEFT JOIN visitors ON visitors.id_visitor = products.id_visitor WHERE hash_product NOT IN ( SELECT menus.hash_product FROM menus ) UNION SELECT products.id_product, menus.hash_product, products.`table`, visitors.name, sum(menus.quantity*menus.product_price) as total, products.card_status, max(menus.created_at) last_update FROM menu.menus LEFT JOIN products ON products.hash_product = menus.hash_product LEFT JOIN visitors ON visitors.id_visitor = products.id_visitor GROUP BY hash_product ORDER BY id_product ASC"); dd($products);
How to execute mysql query in laravel 6?
DB::statement(" INSERT INTO `products` (repost_of_id,token_id,product_details,user) SELECT id,token_id,product_details,".$loginUserId." FROM `products` where id = ".$productId." ");
I hope you get an idea about laravel 6 db statement example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.