murilo

USE whereHas in Poliporph

Posted 10 months ago by murilo

Hello , I am using a Polimorph relation ship , and and tying to make a Query with wherehas , but I cant . I am trying like that -

MODEL

GALLERY MODEL

  public function importable()
    {
        return $this->morphTo();
    }

QUERY

    // SET QUERIES
        $result  = Gallery::select(['id' ,'importable_id' , 'importable_type' , 'url',  'created_at'])

    
            ->when($table_relation_id , function ($query) use ($table_relation_id) {
               
                 $q->whereHas('importable', function ($q) use ($table_relation_id) {
                          return $q->where('id', $table_relation_id);
                   });
           
            })
    ->get()

Does some one had the same problem ?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.