Get Multi Path With Tasks relation instead of 1 path

Posted 3 months ago by Kareimovich

Hi Everybody This is My Controller it returns Path with tasks where Path is in URL and returns tasks only where Task Tags is in Path Tags

    $path = Path::with('pathtags')->where('id', '=', $Path->id)->first();
    $TagArray = $path->pathtags()->pluck('name')->toArray();

      $Path= Enrollee::
           with('path.ProgrammingField')

         ->with(['path.pathtags' => function ($q) use ($TagArray)
      {
                   $q->with(['Tasks' => function ($q) use ($TagArray)
             {$q->has('tasktags', '=', 2)->orderBy('id', 'ASC')
               ->whereDoesntHave('tasktags',
                function ($query) use ($TagArray) {
                    $query->whereNotIn('name', $TagArray);
                }
            )
       ->with('tasktags');
        }]
          )->orderBy('id', 'ASC');
           }])

         ->where( 'user_id' , '=' , Auth::user()->id )
         ->where('Path_id', $Path->id) ->get();

Now I tried To get All User Enroller Paths Using

    $user = User::where('id' ,$user->id)->with('paths.pathtags')->first();
    $pathId = $user->paths->pluck('id');
    $paths = Path::with('pathtags')->whereIn('id',  $pathId)->get();


        foreach ($paths as $path){
            $AllPathsTasgs [] = $path->pathtags->pluck('name');
        } 


  $TagArray = $AllPathsTasgs;
        $Paths= Path::with(['ProgrammingField','pathtags' => function ($q) use ($TagArray)
        {$q->with(['Tasks' => function ($q) use ($TagArray)
           {$q->has('tasktags', '=', 2)->orderBy('id', 'ASC')
           ->whereDoesntHave('tasktags',
           function ($query) use ($TagArray) {
               $query->whereNotIn('name', $TagArray);
           }
       )
               ->with('tasktags')->orderBy('id', 'DESC');
           }]);
       }])
       ->whereIn('id', $pathId)->get();

but Not Working Any ideas

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

Reply to

Use Markdown with GitHub-flavored code blocks.