This demonstration will show you how to get the multi-query stored procedure in the Laravel project. We have seen in a different project that we have a stored procedure that returns data in two separate parts like the below image:
To solve the problem first we have to create a route.
routes/web.php
Route::get('/get_data', [SampleController::class, 'get_data'])->name('get_data');
if we run the usp_get_data() in the Laravel project, we will get the data. For that we have to call this stored procedure like below:
public function get_data()
{
$conn = DB::connection('sqlsrv');
$sql = "EXEC usp_get_data";
$pdo = $conn->getPdo()->prepare($sql);
$pdo->execute();
$res = array();
do {
array_push($res, $pdo->fetchAll());
} while ($pdo->nextRowset());
$data = $res[0];
$data2 = $res[1];
echo '<pre>'; print_r($data);
echo '<pre>'; print_r($data2); exit();
}
if you hit the route, you will get the data as you want.
Hope this might help you in the development journey.
Read More: How to Export large data into CSV format in Laravel