我必须在我的 postgres 数据库上架构我想wherehas
在我的关系上使用 eloquent 但它没有按预期工作。知道我应该在这里做什么吗?
到目前为止我做了什么:
我的第一次连接模型:
class Campaign extends Model
{
protected $table = "CampaignLevel";
protected $connection='pgsql1';
public function opco()
{
return $this->belongsTo(Opco::class);
}
第二个连接
class Opco extends Model
{
protected $hidden = ['pivot'];
protected $connection='pgsql';
现在简单的查询效果很好,但是当我尝试使用 where has 这会给我这样的例外
$query->whereHas("opco", function ($q) {
return $q->whereIn("region", [1,2,3]);
});
错误 :
未定义表:7 错误:关系“opcos”不存在第 1 行:...84、$85、$86、$87、$88) 并且存在
正如我提到的那样简单的查询$query->with('opco')->find(99)->opco->name
效果很好