简体   繁体   中英

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

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?

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)?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM