Laravel View return different Data from Controller

Posted 2 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->has('tasktags', '=' , 2)->with('tasktags');

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>



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.