vendredi 26 octobre 2018

Getting duplicate values Eloquent Laravel

I have a categories table with colunms
id,
category_name,
slug,
parent_id,

In my Category model i have

  public function children()  
  {  
    return $this->hasMany('App\Category','parent_id','id');  
  }

In my controller i have

 public function index()
{
    //
    $categories = Category::whereNull('parent_id')   
                           ->orderBy('category_name','desc')
                           ->get();
    return view('admin.category.index',compact('categories'));
}   

In my blade template i have

 <ul>
     @foreach($categories as $category)
      <li>
         <ul>
            @foreach($category->children  as $child)
              <li></li>
            @endforeach
         </ul>
       </li>
     @endforeach
 </ul>

My problem is, i get duplicate category names



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2AuR9Qp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire