Below is my mongodb function that is stored in Mongodb.
db.system.js.save( { _id: \"echoFunction\", value : function(x) { return x; } }
You can use following code snippet from laravel to execute your mongoDB function.
$cursor = DB::connection('mongodb')->command(array('eval' => 'echoFunction("4")')); $data = $cursor->toArray(); dd($data);
Try and let me know if it works.