Home > Back-end >  How can I include a procedure in my Eloquent ORM laravel select?
How can I include a procedure in my Eloquent ORM laravel select?

Time:11-23

How can I include a procedure in my Eloquent ORM select laravel?

I would like to call my procedure call pro_get_products_in_stock(0) function inside my select, as in the block below:

 $list = Product::query()->select(DB::raw('call pro_get_products_in_stock(0)'))->get();

Does anyone know how to do this?

CodePudding user response:

You can't use Eloquent for this operation.

What you can use is the Query builder.

$query = DB::select('call pro_get_products_in_stock(?)', [0]);
$result = collect($query);

Note, I have not tested it yet, this answer is based on an article of Medium and a SO answer.

https://medium.com/@smayzes/stored-procedures-in-laravel-60e7cb255fc9

How to call Stored Procedure with Eloquent (Laravel)?

  • Related