The issue is that the flash message is only displayed once because the Livewire component is not being re-rendered after the delete action. To fix this, you can use Livewire's redirect method to reload the page after the delete action.
Here's an updated version of the deleteProduct method:
public function deleteProduct(int $productId): void
{
Product::where('id', $productId)->delete();
session()->flash('success-message', 'Post successfully deleted.');
$this->redirect(route('products.index'));
}
By calling $this->redirect(route('products.index')), the Livewire component will be re-rendered, and the flash message will be displayed again.
Make sure to replace 'products.index' with the actual route name of the page where the Livewire component is being used.
Also, ensure that you have the necessary route defined in your routes file for the products.index route.
With this change, the flash message should appear every time a post is deleted without reloading the page.