File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 5
5
namespace MongoDB \Laravel \Eloquent ;
6
6
7
7
use Illuminate \Database \Eloquent \Builder as EloquentBuilder ;
8
- use MongoDB \Driver \Cursor ;
8
+ use MongoDB \Driver \CursorInterface ;
9
9
use MongoDB \Driver \Exception \WriteException ;
10
10
use MongoDB \Laravel \Connection ;
11
11
use MongoDB \Laravel \Helpers \QueriesRelationships ;
@@ -177,7 +177,7 @@ public function raw($value = null)
177
177
$ results = $ this ->query ->raw ($ value );
178
178
179
179
// Convert MongoCursor results to a collection of models.
180
- if ($ results instanceof Cursor ) {
180
+ if ($ results instanceof CursorInterface ) {
181
181
$ results = iterator_to_array ($ results , false );
182
182
183
183
return $ this ->model ->hydrate ($ results );
Original file line number Diff line number Diff line change 25
25
use MongoDB \BSON \UTCDateTime ;
26
26
use MongoDB \Builder \Stage \FluentFactoryTrait ;
27
27
use MongoDB \Driver \Cursor ;
28
+ use MongoDB \Driver \CursorInterface ;
28
29
use Override ;
29
30
use RuntimeException ;
30
31
use stdClass ;
@@ -934,7 +935,17 @@ public function raw($value = null)
934
935
{
935
936
// Execute the closure on the mongodb collection
936
937
if ($ value instanceof Closure) {
937
- return call_user_func ($ value , $ this ->collection );
938
+ $ results = call_user_func ($ value , $ this ->collection );
939
+
940
+ if ($ results instanceof CursorInterface) {
941
+ $ results = $ results ->toArray ();
942
+ }
943
+
944
+ if (is_array ($ results ) || is_object ($ results )) {
945
+ $ results = $ this ->aliasIdForResult ($ results );
946
+ }
947
+
948
+ return $ results ;
938
949
}
939
950
940
951
// Create an expression for the given value
You can’t perform that action at this time.
0 commit comments