每个人,我下面的代码都会返回具有1个以上标记和 在我将其传递给View之前,代码运行正常。然后,它将返回所有任务,甚至是只有一个标签的任务。
我的代码
$posts = Path::with(['pathtags' => function ($q) {
$q->with(['Tasks'=>function($q){
$q->has('tasktags', '=' , 2)->with('tasktags');
}]);
}])
->where('id','>',1)->get();
我的观点
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