Hi, i'm not sure how to explain my problem but i'll give it a try.
I have 3 tables: pages, languages and language_page.
This is 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 return a record from the page table where language_id is a certain id, and where slug is a certain text.
This is what i got so far:
Page::whereHas('languages', function($q) use ($language_id) {
$q->where('language_id', $language_id);
})
->get();
My problem: how can i add a where clause with the column slug (from the pivot table language_page) ?
i hope this makes any sense at all..