I am not sure how to explain my problem, but I will try.
I am using Laravel 5 and I have 3 tables:
- pages
- Languages
- language_page
Here's what my models look like: Page Model:
public function languages()
{
return $this->belongsToMany('App\Language', 'language_page')
->withPivot('title', 'content', 'slug', 'meta_title', 'meta_description')
->orderBy('main', 'desc');
}
Language Model:
public function pages()
{
return $this->belongsToMany('App\Page')
->withPivot('title', 'content', 'slug', 'meta_title', 'meta_description');
}
What I want to do is return an entry from the page table where language_id is the specific identifier and slug is the specific text.
This is what I got so far: EDIT:
Page::with(['languages' => function($q) use($language_id, $slug) {
$q->where('language_id', $language_id);
$q->wherePivot('slug', $slug);
}])
->first();
My problem: how can I add a where clause using a column column (from the pivot table table language_page)?
I hope this makes sense at all.
source
share