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) {
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?
php mongodb eloquent laravel jenssegers-mongodb
Hollings
source share