Get Multi Path With Tasks relation instead of 1 path

Posted 1 month 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.pathtags' => function ($q) use ($TagArray)
                   $q->with(['Tasks' => function ($q) use ($TagArray)
             {$q->has('tasktags', '=', 2)->orderBy('id', 'ASC')
                function ($query) use ($TagArray) {
                    $query->whereNotIn('name', $TagArray);
          )->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')
           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.

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


Reply to

Use Markdown with GitHub-flavored code blocks.