Updated June 2026. Tested on Laravel 13 and PHP 8.4.
A reader once asked me whether you can call a database stored procedure from Laravel. You can, and these days it is clean. Eloquent itself does not call procedures, but the DB facade does, with bound parameters and no raw PDO juggling. The old way of reaching into Doctrine DBAL and PDO by hand is long gone, so ignore any tutorial still doing that.
Call a procedure that returns rows
If your procedure runs a SELECT and returns a result set, use DB::select. The CALL statement goes in, your parameters bind safely with ? placeholders, and you get back an array of rows.
use Illuminate\Support\Facades\DB;
$results = DB::select('CALL get_active_products(?, ?)', [
$categoryId,
$limit,
]);
$results is an array of plain objects, one per row, exactly like any other DB::select. The placeholders keep it safe from SQL injection, so never concatenate values into the string.
Call a procedure that does not return rows
If the procedure just does work, an insert or an update for example, and returns nothing, use DB::statement instead.
DB::statement('CALL archive_old_orders(?)', [$beforeDate]);
Use it in a controller
Putting it together, a controller method that returns the procedure's rows as JSON is short.
use Illuminate\Support\Facades\DB;
public function activeProducts(Request $request)
{
return DB::select('CALL get_active_products(?, ?)', [
$request->integer('category'),
$request->integer('limit', 10),
]);
}
A note on a specific connection
If the procedure lives on a database that is not your default connection, name the connection first.
$results = DB::connection('reporting')->select('CALL monthly_summary(?)', [$month]);
That is all there is to it now. DB::select for procedures that return rows, DB::statement for those that do not, bound parameters either way. Questions about calling stored procedures from Laravel are welcome in the comments.
All comments ()
No comments yet
Be the first to leave a comment on this post.