How to use Stored Procedures in Laravel?

0 votes
How to create a Stored Procedure? Can Anyone explain me out there??
Mar 24 in Laravel by kartik
• 27,360 points
919 views

1 answer to this question.

0 votes

Hey,

To create a Stored Procedure you can execute given code in your MySQL query builder directly or use phpmyadmin for this.

DROP PROCEDURE IF EXISTS `get_subcategory_by_catid`;
delimiter ;;
CREATE PROCEDURE `get_subcategory_by_catid` (IN idx int)
BEGIN
SELECT id, parent_id, title, slug, created_at FROM category WHERE parent_id = idx AND status = 1 ORDER BY title;
END
;;
delimiter ;

After this, you can use this created procedure in your code in Laravel.

How to use stored procedure in Laravel

$getSubCategories = DB::select(
   'CALL get_subcategory_by_catid('.$item->category_id.')'
);

Thank you!!

answered Mar 24 by Niroj
• 58,960 points

Related Questions In Laravel

0 votes
1 answer

How to use multiple databases in Laravel?

Hello @kartik, Laravel has inbuilt support for multiple ...READ MORE

answered Jul 30 in Laravel by Niroj
• 58,960 points
52 views
0 votes
1 answer

How to use API Routes in Laravel?

Hello @kartik, You call it by http://localhost:8080/api/test ...READ MORE

answered Aug 10 in Laravel by Niroj
• 58,960 points
283 views
0 votes
1 answer

How to only use created_at in Laravel?

Hello @kartik, Eloquent does not provide such functionality ...READ MORE

answered Aug 11 in Laravel by Niroj
• 58,960 points
73 views
0 votes
1 answer

How to use GROUP_CONCAT in laravel?

Hello @kartik, You can use relations as query ...READ MORE

answered 3 days ago in Laravel by Niroj
• 58,960 points
9 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 58,960 points
2,205 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 58,960 points
244 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 58,960 points
191 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 58,960 points
2,760 views
0 votes
1 answer

How to use mail() in laravel?

Hello, Laravel provides a powerful and clean API ...READ MORE

answered Mar 24 in Laravel by Niroj
• 58,960 points
85 views
0 votes
1 answer

How to make a constant and use globally in laravel?

Hii, You can create a constants.php page in config folder ...READ MORE

answered Mar 24 in Laravel by Niroj
• 58,960 points
94 views