Good Day
this is a absolute newbie question,
how can I call a stored procedure using eloquent? some examples that i see
use Illuminate\Database\Query;
$data = DB::statement(DB::raw("CALL nameofSP('1', '2');"));
but when i try to run the app showme erros like
Fatal error: Class 'DB' not found
Try something like this:
$dbConn = \Illuminate\Database\Capsule\Manager::connection();
$dbConn->statement ("CALL nameofSP('1', '2');");
Warning, I didn’t test this, but it should work.
in this update… i got some advance, let me show
first you must correct instance eloquent on dependencies.php for ex.
...
$capsule = new \Illuminate\Database\Capsule\Manager;
$capsule->addConnection($container['settings']['db']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
$container['db'] = function ($c) use ($capsule) {
return $capsule;
};
...
then you can call raw query as:
$result = $this->db->connection()->statement("CALL nameofSP(:param1, :param2);", array(':param1' => $val1, ':param2' => $val2));
this return
var_dump($result);
bool(true)
but not show the array of results… in my case i change statement for select and it works…
$result = $this->db->connection()->select("CALL nameofSP(:param1, :param2);", array(':param1' => $val1, ':param2' => $val2));