小编Hol*_*ngs的帖子

Laravel + Jenssegers\Mongodb:'WhereHas' 和 'Has' 返回空集合

我现在主要在两个模型上工作,Formand 和Notification,并且建立了多对多关系并适用于大多数 Eloquent 命令,除了whereHasand has。两者都只返回一个空数组,[]

似乎开发人员过去在让它工作时遇到了麻烦,但似乎在这里已经解决

这是我到目前为止所拥有的以及我尝试过的示例:

表单.php

class Form extends Eloquent {
    protected $connection = 'mongodb';

    public function notifications(){
        return $this->belongsToMany('App\Api\Forms\Notification', null, 'form_ids', 'notification_ids');
    }

}
Run Code Online (Sandbox Code Playgroud)

通知.php

class Notification extends Eloquent {
    protected $connection = 'mongodb';

    public function forms()
    {
        return $this->belongsToMany('App\Api\Forms\Form', null, 'notification_ids', 'form_ids');
    }    
}
Run Code Online (Sandbox Code Playgroud)

通知控制器.php

<?php

namespace App\Http\Controllers;
use App\Api\Forms\Notification;
use App\Api\Forms\Form;

class NotificationController extends Controller
{

    public function …
Run Code Online (Sandbox Code Playgroud)

php mongodb laravel eloquent jenssegers-mongodb

5
推荐指数
0
解决办法
1031
查看次数

标签 统计

eloquent ×1

jenssegers-mongodb ×1

laravel ×1

mongodb ×1

php ×1