Laravel + Jenssegers \ Mongodb: "WhereHas" and "Has" returns an empty collection

I mainly work on two models, Form and Notification , and the many-to-many relationship is set up and works for most Eloquent commands, with the exception of whereHas and has . Both just return an empty array, [] .

It looks like the developer had a problem with getting this to work in the past , but seems to have solved it here .

Here is an example of what I have so far, and what I have tried:

form.php

 class Form extends Eloquent { protected $connection = 'mongodb'; public function notifications(){ return $this->belongsToMany('App\Api\Forms\Notification', null, 'form_ids', 'notification_ids'); } } 

Notification.php

 class Notification extends Eloquent { protected $connection = 'mongodb'; public function forms() { return $this->belongsToMany('App\Api\Forms\Form', null, 'notification_ids', 'form_ids'); } } 

NotificationController.php

 <?php namespace App\Http\Controllers; use App\Api\Forms\Notification; use App\Api\Forms\Form; class NotificationController extends Controller { public function getByFormTitle($form_title) { // This code retuns the relationship as expected. // Any forms that are assigned to it are returned. // $n = Notification::first(); // $n->forms()->get(); // This also returns the relationship correctly, same as before. // $f = Form::first(); // $f->notifications()->get(); // Nearly identical to the Laravel docs. This returns an empty array, [] $notifications = Notification::whereHas('forms', function ($query) use ($form_title) { $query->where('form_title', $form_title); })->get(); return $notifications; } } 

I get the same result if I use Notification::has('form')->get() .

So my question is:

Is it possible to use whereHas and has in Jenssegers\Mongodb Eloquent ? Should I use a different syntax than the official Laravel documentation for it, or should I make a raw Mongo request for it?

+2
php mongodb eloquent laravel jenssegers-mongodb
source share

No one has answered this question yet.

See similar questions:

7
Laravel Mongo Many for many relationships that do not work

or similar:

nine
Laravel Jenssegers MongoDb Relationships not working?
2
Php variable doesn't go to whereHas function - Laravel Eloquent
2
Use MongoDB with Laravel 5.3
2
Laravel 5.5 Mongo DB Error
2
MongoDB query for a summary function that returns an empty result
2
Laravel MongoDB self reference
one
How to sum two fields in laravel mongodb?
one
laravel mongodb clicks an element on an existing array in doc_
one
Problem with Laravel 5.2 and jenssegers / laravel-mongodb
0
How to access data returned in MongoDB course in laravel controller?

All Articles