try
<a href="#" wire:click.prevent="getCatId({{ $cat->id}})">
... assuming your id is numeric
and sort this out
$this->getCatId = Category::findOrFail($id);
you can't have a public property and a method with identical names
Hi all,
I've Category class that has manyToone relation with posts, i'm showing category's name with the number of its posts, then when a user click on it, i'm taking the category id to CategorySideList livewire and getting all its posts and then showing them to user in category-side-list livewire component, what i got from the doc, that i can pass id to livewire class CategorySideList as wire:click="getCatId{{category_id}}" but its not working,
sending category id
<div class="common-right-content widget-item">
<h3>Categories</h3>
<ul>
@if($sidebar_categories && $sidebar_categories-> count() > 0)
@foreach ($sidebar_categories as $cat )
<li>
<a href="wire:click='getCatId({{ $cat->id}})'">{{ $cat->title }} ({{ $cat->posts->count() }})</a>
</li>
<li>
@endforeach
@endif
</ul>
</div>
then getting the categor id in CategorySideList livewire
class CategorySideList extends Component
{
public $getCatId;
use WithPagination;
protected $paginationTheme = 'bootstrap';
public function getCatId($catId){
dd($catId);
$this->getCatId = Category::findOrFail($id);
}
public function render()
{
$categories_posts = $getCatId->posts()->orderBy('id','desc')->paginate(6);
return view('livewire.category-side-list',compact('categories_posts'));
}
}
i checked in getCatId() method dd($catId); but its not called, it means i'm not even sending the id here, i appreciate your help !
Please or to participate in this conversation.