Laravel 5 枢轴 table 问题

Laravel 5 pivot table issue

我不确定如何解释我的问题,但我会试一试。

我正在使用 Laravel 5 并且我有 3 个 table:

这是我的模型的样子: 页面模型:

public function languages()
{
    return $this->belongsToMany('App\Language', 'language_page')
                ->withPivot('title', 'content', 'slug', 'meta_title', 'meta_description')
                ->orderBy('main', 'desc');
}

语言模型:

public function pages()
{
    return $this->belongsToMany('App\Page')
                ->withPivot('title', 'content', 'slug', 'meta_title', 'meta_description');
}

我想做什么 return 来自页面的一条记录 table 其中 language_id 是某个 id,而 slug 是某个文本。

这是我目前得到的:编辑:

Page::with(['languages' => function($q) use($language_id, $slug) {
                        $q->where('language_id', $language_id);
                        $q->wherePivot('slug', $slug);
                    }])
                    ->first();

我的问题:如何添加带有列别名的 where 子句(从主元 table language_page)?

我希望这完全有意义..

Eloquent 的 BelongsToMany class 有一个

wherePivot()

允许您将 WHERE 子句直接应用于数据透视 table 的方法,请参阅:

https://github.com/laravel/framework/blob/5.1/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php#L111