At the end of the last summer, I received the following email in my inbox, from one of my follower on techalyst.com, seeking my help whether it is possible to call Database Stored Procedure with Laravel Eloquent,
Event though it is not possible to execute MySQL Stored procedure with Laravel Eloquent ORM directly , you can use Laravel Query builder approach in the following style.
first import the following namespaces
on top of the controller file or in the file where you want to call the Stored Procedure.
use Illuminate\Support\Facades\DB;
use Doctrine\DBAL\Driver\PDOConnection;
and following lines of code show how to call the stored procedure, you can bind parameters required by your stored procedure.
$db = DB::connection()->getPdo();
$db->setAttribute(PDOConnection::ATTR_ERRMODE, PDOConnection::ERRMODE_EXCEPTION);
$db->setAttribute(PDOConnection::ATTR_EMULATE_PREPARES, true);
$queryResult = $db->prepare('call yourstoredprocedurename(?,?)');
$queryResult->bindParam(1, $parameter1);
$queryResult->bindParam(2, $parameter2
,PDOConnection::PARAM_STR);
$queryResult->execute();
$results = $queryResult->fetchAll(PDOConnection::FETCH_ASSOC);
$queryResult->closeCursor();
return $results;
if you have any questions regarding "how to call MySQL Stored Procedure with Laravel Eloquent ORM, Query Builder", please feel free to leave your comment bellow.
Be the first one to write a response :(
{{ reply.member.name }} - {{ reply.created_at_human_readable }}