Skip to content

Commit 7330a6c

Browse files
committed
Merge pull request #248 from JesseObrien/master
Adding a check for exposable json attributes.
2 parents 44f9eeb + 11107ad commit 7330a6c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Jenssegers/Mongodb/Model.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ abstract class Model extends \Jenssegers\Eloquent\Model {
2828
*/
2929
protected $primaryKey = '_id';
3030

31+
/**
32+
* Allow json attributes to be exposable. This is mainly for
33+
* relations that can be kept alive in a toJson()
34+
*
35+
* @var array
36+
*/
37+
protected $expose = [];
38+
3139
/**
3240
* The connection resolver instance.
3341
*
@@ -284,7 +292,7 @@ public function attributesToArray()
284292
// internal array of embedded documents. In that case, we need
285293
// to hide these from the output so that the relation-based
286294
// attribute can take over.
287-
else if (starts_with($key, '_'))
295+
else if (starts_with($key, '_') and ! in_array($key, $this->expose))
288296
{
289297
$camelKey = camel_case($key);
290298

0 commit comments

Comments
 (0)