Prevent Foreach To return Duplicated Tasks

Posted 7 months ago by Kareimovich

hi, everybody, I'm trying to Prevent To return duplicated Tasks in relation

A Path has many Tags, every Tag has Many Tasks, every Task has many tags

My Code Prevent to return duplicated Tasks in Tag but I need to Prevent Duplicated Tasks in All Tasks of Path

My Controller

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

My Blade

  @foreach ($Paths as $Path)
      <h2> {{$Path->name}}</h2>
      @foreach ($item->pathtags as $Tag)

        @php $a=array(); @endphp 
            @foreach ($Tag->Tasks as $Task)
               @if (!in_array($Task->task_name,$a))
                  <li> Task :: {{ $Task->task_name }} </li>
       <li> Task :: Duplicated </li>

@foreach ($a as $item)
   <li>Array Task :::  {{$item}}</li>


ScreenShot For Ouput of blade

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

Reply to

Use Markdown with GitHub-flavored code blocks.