need to compare relation name to array

Posted 8 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->has('tasktags', '=' , 2)->with('tasktags');

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');

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 = tag_task.task_id where tag_task.tag_id in (1, 2) and (select count() from tags inner join tag_task on = tag_task.tag_id where = tag_task.task_id) = 2 and name in (HTML5, PHP))

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

Reply to

Use Markdown with GitHub-flavored code blocks.