Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call Stored Procedure with Eloquent (Laravel)?

There is no standard procedure mentioned in documentation that how to call a stored procedure in MYSQL in laravel with Eloquent syntax.

I mean is there any way to call stored procedure in mysql with help of eloquent syntax like

$result = StoredProcedures::my_custom_procedure(param1, param2);
return view('welcome')->with('result',$result);

Is there any way to call and fetch results from stored procedures with pure eloquent syntax(purely eloquent way).

Thanks. Small examples are highly encouraged .

like image 420
Hassan Raza Avatar asked Jun 04 '17 13:06

Hassan Raza


1 Answers

As everyone has mentioned, you can't call a stored procedure in Laravel with Eloquent syntax. You can transfer the result of your query to a collection which will give you all of the collection functionality.

$queryResult = DB::select('call my_custom_procedure(?, ?)', [1,2]);

$result = collect($queryResult);

return view('welcome')->with('result',$result);
like image 108
whoacowboy Avatar answered Sep 19 '22 17:09

whoacowboy