Just trying to do some relationship on Laravel with MongoDB, but I'm getting a null on my requests. I have a "passengers" collection with a trip_id. Something like this:
{
"id":"5d680fd36882d19e782d67bd",
"trip_id":"5d680fcb6882d19e782d6380",
"name":"Lee Jones"
}
And a collection with the name "lotes" that contain documents that each one has many trips. Something like this:
{
"_id":"5d680fca6882d19e782d60f6",
"user_id":"5d680fca6882d19e782d60b4",
"date_to_ride":"2019-08-29T22:00:00.000+00:00",
"trips":[
{
"trip_id":"5d680fcb6882d19e782d6380",
"car":"VW Golf"
}
]
}
So I want to get all passengers that has same trip_id when I'm getting the trip info.
This is my relation on the Trip model:
public function passengers()
{
return $this->hasMany(\App\Passenger::class, 'trip_id', 'lotes.trips.trip_id')->whereNotNull('trip_id');
}
And this is my result on the json:
"passengers": []
Any idea?