@@ -751,7 +751,7 @@ public function query()
751
751
$ query ["type " ] = $ this ->getType ();
752
752
}
753
753
754
- if ($ this ->model && $ this ->useGlobalScopes ){
754
+ if ($ this ->model && $ this ->useGlobalScopes ) {
755
755
$ this ->model ->boot ($ this );
756
756
}
757
757
@@ -922,32 +922,36 @@ protected function getAll($result = [])
922
922
923
923
$ new = [];
924
924
925
- foreach ( $ result [ "hits " ][ " hits " ] as $ row ) {
925
+ if ( array_key_exists ( "hits " , $ result ) ) {
926
926
927
- $ model = $ this -> model ? new $ this -> model ( $ row [ " _source " ], true ) : new Model ( $ row [ " _source " ], true );
927
+ foreach ( $ result [ " hits " ][ " hits " ] as $ row ) {
928
928
929
- $ model ->setConnection ($ model ->getConnection ());
930
- $ model ->setIndex ($ row ["_index " ]);
931
- $ model ->setType ($ row ["_type " ]);
929
+ $ model = $ this ->model ? new $ this ->model ($ row ["_source " ], true ) : new Model ($ row ["_source " ], true );
932
930
933
- // match earlier version
931
+ $ model ->setConnection ($ model ->getConnection ());
932
+ $ model ->setIndex ($ row ["_index " ]);
933
+ $ model ->setType ($ row ["_type " ]);
934
934
935
- $ model ->_index = $ row ["_index " ];
936
- $ model ->_type = $ row ["_type " ];
937
- $ model ->_id = $ row ["_id " ];
938
- $ model ->_score = $ row ["_score " ];
935
+ // match earlier version
939
936
940
- $ new [] = $ model ;
941
- }
937
+ $ model ->_index = $ row ["_index " ];
938
+ $ model ->_type = $ row ["_type " ];
939
+ $ model ->_id = $ row ["_id " ];
940
+ $ model ->_score = $ row ["_score " ];
941
+
942
+ $ new [] = $ model ;
943
+ }
944
+
945
+ $ new = new Collection ($ new );
942
946
943
- $ new = new Collection ($ new );
947
+ $ new ->total = $ result ["hits " ]["total " ];
948
+ $ new ->max_score = $ result ["hits " ]["max_score " ];
949
+ $ new ->took = $ result ["took " ];
950
+ $ new ->timed_out = $ result ["timed_out " ];
951
+ $ new ->scroll_id = isset ($ result ["_scroll_id " ]) ? $ result ["_scroll_id " ] : NULL ;
952
+ $ new ->shards = (object )$ result ["_shards " ];
944
953
945
- $ new ->total = $ result ["hits " ]["total " ];
946
- $ new ->max_score = $ result ["hits " ]["max_score " ];
947
- $ new ->took = $ result ["took " ];
948
- $ new ->timed_out = $ result ["timed_out " ];
949
- $ new ->scroll_id = isset ($ result ["_scroll_id " ]) ? $ result ["_scroll_id " ] : NULL ;
950
- $ new ->shards = (object )$ result ["_shards " ];
954
+ }
951
955
952
956
return $ new ;
953
957
}
@@ -960,9 +964,9 @@ protected function getAll($result = [])
960
964
protected function getFirst ($ result = [])
961
965
{
962
966
963
- $ data = $ result ["hits " ]["hits " ];
967
+ if ( array_key_exists ( " hits " , $ result ) && count ( $ result ["hits " ]["hits " ])) {
964
968
965
- if ( count ( $ data)) {
969
+ $ data = $ result [ " hits " ][ " hits " ];
966
970
967
971
if ($ this ->model ) {
968
972
$ model = new $ this ->model ($ data [0 ]["_source " ], true );
@@ -1393,7 +1397,8 @@ function __call($method, $parameters)
1393
1397
/**
1394
1398
* @return $this
1395
1399
*/
1396
- public function withoutGlobalScopes (){
1400
+ public function withoutGlobalScopes ()
1401
+ {
1397
1402
1398
1403
$ this ->useGlobalScopes = false ;
1399
1404
0 commit comments