this is Posts class:
public $posts, $post;
public function mount(){
$this->posts = Post::all();
}
public function getDtata($id){
$post = Post::find($id);
$this->post = $post;
}
public function render()
{
return view('livewire.posts');
}
and Posts component:
<div class="post" x-data="{open:false}">
@foreach($posts as $post)
<div>
<h1>{{ $post->name }}</h1>
<h3>{{ $post->body }}</h3>
<img @click="open = !open" wire:click="getDtata({{ $post->id }})" src="{{ $post->image }}" alt="">
</div>
@endforeach
<livewire:post>
</div>
this is Post component:
<div x-show="open">
<h1>{{ $post->name }}</h1>
<h3>{{ $post->body }}</h3>
<img src="{{ $post->image }}" alt="">
</div>
the class is:
public $post;
public function mount(\App\Post $post) {
$this->post = $post;
}
public function render()
{
return view('livewire.post');
}
How I can pass the id of clicked which send getData to Posts and get that id in Post?