Laravel View return different Data from Controller

Posted 5 months ago by Kareimovich

Hi everybody, My code here is returning tasks that have more than 1 Tag and the code is working fine until I pass it to view it returns all tasks even tasks that have one tag My Code

My Controller :

$posts = Path::with(['pathtags' => function ($q)  {
        $q->with(['Tasks'=>function($q){
         $q->has('tasktags', '=' , 2)->with('tasktags');
          }]);
        }])
->where('id','>',1)->get();

My View : return view ('task',compact('posts'));

@foreach ($posts as $Task)
<h2>{{ $Task->name }}</h2>

@foreach ($Task->pathtags as $Tag)
<h3>{{ $Tag->name }}</h3>

@foreach ($Tag->tasks as $Ta)
<h2>{{ $Ta->task_name }}</h2>

@endforeach

@endforeach
@endforeach

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

Reply to

Use Markdown with GitHub-flavored code blocks.