need to compare relation name to array

Posted 3 months ago by Kareimovich

Hi, Everybody, I need to get data where tasktags name is in $TagArray using wherein

    $TagsArray = Path::with('pathtags')->first();

$TagArray = [];

foreach ($TagsArray->pathtags as $tags) {
    $TagArray[] = $tags->name;
} 
    $TCompare = Path::with(['pathtags' => function ($q)  {
        $q->with(['Tasks'=>function($q){
            $q->has('tasktags', '=' , 2)->with('tasktags');
        }]);
    }])
    ->first();

I have tried

       $TCompare = Path::with(['pathtags' => function ($q) use ($TagArray) { 
               $q->with(['Tasks'=>function($q) use ($TagArray) { 
           $q->has('tasktags', '=' , 2)->whereIn('name', $TagArray)->with('tasktags');
              }]);
            }])->first();

but I get this error

Illuminate \ Database \ QueryException (42S22) SQLSTATE[42S22]: Column not found: 1054 Unknown column 'name' in 'where clause' (SQL: select tasks., tag_task.tag_id as pivot_tag_id, tag_task.task_id as pivot_task_id from tasks inner join tag_task on tasks.id = tag_task.task_id where tag_task.tag_id in (1, 2) and (select count() from tags inner join tag_task on tags.id = tag_task.tag_id where tasks.id = tag_task.task_id) = 2 and name in (HTML5, PHP))

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.