oxbir
4 months ago
897
12
Laravel

Property [id] does not exist on this collection instance.

Posted 4 months ago by oxbir

Look at my codes and I have three tables,

  • galleries
  • categories
  • category_gallery

Gallery.php

public function categories()
{
    return $this->belongsToMany(Category::class);
}

GalleryController.php

public function gallery()
{
    $galleries = Gallery::whereNotNull('image')->latest()->paginate(25);
    $categories = Category::where('parent_id', 42)->with('galleries')->get();
    return view('Home.galleries', compact('galleries', 'categories'));
}

galleries.blade.php

 {{ dd($gallery->categories->id) }}

I get this error

Property [id] does not exist on this collection instance.

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