Skip to content

Commit 35f83bc

Browse files
committed
Add conditional return type to Builder::raw()
for both the Eloquent and the Query builder, so that developers can understand that the return type will either be a `Collection` or an `Expression` based on the argument that's passed to `raw()`
1 parent ea742b8 commit 35f83bc

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Eloquent/Builder.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Database\Eloquent\Collection;
99
use Illuminate\Database\Eloquent\Model;
1010
use MongoDB\BSON\Document;
11+
use MongoDB\Builder\Expression;
1112
use MongoDB\Builder\Type\QueryInterface;
1213
use MongoDB\Builder\Type\SearchOperatorInterface;
1314
use MongoDB\Driver\CursorInterface;
@@ -229,7 +230,11 @@ public function decrement($column, $amount = 1, array $extra = [])
229230
return parent::decrement($column, $amount, $extra);
230231
}
231232

232-
/** @inheritdoc */
233+
/**
234+
* @return ($value is callable ? Collection : ($value is null ? Collection : Expression))
235+
*
236+
* @inheritdoc
237+
* */
233238
public function raw($value = null)
234239
{
235240
// Get raw results from the query builder.

src/Query/Builder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,11 @@ public function lists($column, $key = null)
964964
return $this->pluck($column, $key);
965965
}
966966

967-
/** @inheritdoc */
967+
/**
968+
* @return ($value is callable ? Collection : ($value is null ? Collection : Expression))
969+
*
970+
* @inheritdoc
971+
* */
968972
public function raw($value = null)
969973
{
970974
// Execute the closure on the mongodb collection

0 commit comments

Comments
 (0)