我现在主要在两个模型上工作,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)