This is what my database structure looks like (this document belongs to USER model):
{
"_id" : ObjectId("58a331ffb854d000f97862f3"),
"first_name" : "John",
"last_name" : "Doe",
"email" : "[email protected]",
"password" : "$2y$10$fIuECeTqvSUY1g.VPgWxceEzB0/q2OtgDXlm9ZTqwY77U74hVEe6q",
"updated_at" : ISODate("2017-02-14T16:36:15.079Z"),
"created_at" : ISODate("2017-02-14T16:36:15.079Z"),
"Condition" : [
{
"d_name" : "Asthma",
"d_isTreated" : "No",
"d_diagnosed_at" : "2017-02-14"
},
{
"d_name" : "Bronchitis",
"d_isTreated" : "No",
"d_diagnosed_at" : "2017-02-14"
},
{
"d_name" : "Hepatitis C",
"d_isTreated" : "No",
"d_diagnosed_at" : "2017-02-14"
}
]
}
My USER model:
<?php
namespace App;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class User extends Eloquent
{
public function conditions()
{
return $this->embedsMany('Condition');
}
}
My Condition model:
<?php
namespace App;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class Condition extends Eloquent
{
//
}
The system seems to not be able to return embedded documents.
SOLUTION
At the time of writing this comment, this extension does not fully support Laravel 5.4. If you are having similar problems with model class relationships, remember that, as of Laravel 5.4, plain class names will not work anymore. If you reference your class anywhere in your application, you need to specify which namespace it belongs to.
So in this embedsMany case, it would be:
return $this->embedsMany('App/Condition');
instead of:
return $this->embedsMany('Condition');
Most helpful comment
SOLUTION
At the time of writing this comment, this extension does not fully support Laravel 5.4. If you are having similar problems with model class relationships, remember that, as of Laravel 5.4, plain class names will not work anymore. If you reference your class anywhere in your application, you need to specify which namespace it belongs to.
So in this
embedsManycase, it would be:instead of: