laravel for loop not working in Nested function

Posted 1 month ago by Kareimovich

Hi Everyone I have Multi-Array AllPathsTasgs[] that has 2 path tags That has in the example

  [
 [
 "php",
 "HTML5",
 "CSS3",
"XML"
],
 [
"HTML5",
"CSS3",
"JavaScript",
 "Bootstrab"
]
 ]

I'm Trying to get to Tasks that have tags like path tags using the line below

           $query->whereNotIn('name', $AllPathsTasgs[$x]);

and is working fine with first path but it use first array in every path that means

the first path should be like

             $query->whereNotIn('name', $AllPathsTasgs[$x]); and x here = 0

and this is ok but the problem is in the next path

         $query->whereNotIn('name', $AllPathsTasgs[$x]); x = 0 not 1

don't know why this happens

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