Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel-5 return eloquent object when running MySQL stored procedure

I would like to know if it's possible to return a MySQL stored procedure call as an eloquent object.

The below call works fine for me, but $result always returns an array instead of the usual Eloquent object.

$result = DB::select('call bookings_by_voucher()');

Does anyone know how to return this as an object, so that I can use ->count(), ->get() etc.

like image 473
V4n1ll4 Avatar asked Oct 30 '22 22:10

V4n1ll4


1 Answers

You must pass the array into a new instance of your eloquent object.

$booking = new Booking($result);
like image 60
Lance Pioch Avatar answered Nov 08 '22 05:11

Lance Pioch