I'm having trouble retrieving a polymorphic association "where related_object.column_name = x". Let me explain:
I have a number of “pages" in my database, and each page has polymorphic association to different types of “content”. for example :
pages
slug : my-page, id : 1
slug : my-other page, id: 2
music_track table
music_track : id 10, page_id : 1
video table
video : id 20, page_id: 2
image table
image : id 30, page_id: 1
content table
id: 555, contentable_id 10, contentable_type: App\music_track
id: 556, contentable_id 20, contentable_type: App\video
id: 557, contentable_id 30, contentable_type: App\image
I can return all content using Content::all( ), how do I return all content who’s page_id is ‘1’?
I can't seem to use Content::where('page_id', "=", "1"), because page_id is ambiguous, or assumed to be part of the content table. How to a query the RELATED table?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire