return tasks with same tags as path

Posted 1 month ago by Kareimovich

Hi Everyone I have made for loop so I can compare every path tasktags to AllPathsTasgs So I can return only tasks that have same tags like the path tags but it returns tasks that have tags in all path tags any help, please

     foreach ($paths as $path){
          $AllPathsTasgs [] = $path->pathtags->pluck('name');
     }
  
        $posts3 = Path::with(['ProgrammingField','pathtags' => function ($q) use         
          ($AllPathsTasgs)
         {$q->with(['Tasks' => function ($q) use ($AllPathsTasgs)
             {$q->has('tasktags', '=', 2)->orderBy('id', 'ASC')
           ->whereDoesntHave('tasktags',
           
           function ($query) use ($AllPathsTasgs) {
            for ($x = 0; $x < count($AllPathsTasgs); $x++) {
                $query->whereNotIn('name', $AllPathsTasgs[$x]);

            }
           
           }
       )
               ->with('tasktags')->orderBy('id', 'ASC');
                   }]);
            }])
        ->whereIn('id', $pathId)->get();

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.