'Tailwind Flowbite modal issues on Livewire action
I'm having a real hard time using Flowbite's modals with Livewire.
I have a Blade view restaurants.index
rendering the x-layout
Blade component, calls the <livewire:restaurants/>
component, and the modal for creating a new resource. (restaunts.index view code)
The livewire:restaurants/ view component has the following code while, the Restaurants
class component has the following inside.
class Restaurants extends Component
{
use WithPagination;
public $categories;
protected $restaurants;
public function delete($id)
{
Restaurant::find($id)->delete();
}
public function render()
{
$this->categories = Category::where('type', 'Restaurant')->get();
$this->db_restaurants = Restaurant::all();
$google_places_api = new PlacesApi(env('GOOGLE_MAPS_API_KEY'));
$restaurantsGooglePlacesResponse = array();
foreach ($this->db_restaurants as $restaurant) {
$response = $google_places_api->placeDetails($restaurant->google_place_id);
$details = $response['result'];
$photo_reference = array_shift($details['photos'])['photo_reference'];
$photo_url = $google_places_api->photo($photo_reference, $params = ['maxheight' => 400, 'maxwidth' => 400]);
$details['photo_url'] = $photo_url;
$details['internal_restaurant_id'] = $restaurant->id;
$details['internal_created_at'] = $restaurant->created_at;
array_push($restaurantsGooglePlacesResponse, $details);
}
$this->restaurants = collect($restaurantsGooglePlacesResponse)->paginate(8);
return view('livewire.restaurants', ['restaurants' => $this->restaurants]);
}
}
The issue that I'm facing is that, on the first-page loading, each of the three modals is showing and working correctly. Still, when I perform a Livewire action (ex., deleting a record via the delete() method), modals either stop working at all or, if they work, are not appropriately rendered (for example, generated on the top left corner of the page).
This seems to be a peculiar behavior caused by Livewire. Do you have any idea of what can cause this issue and how to solve it?
Solution 1:[1]
What you can do to handle this issue is to put a button that will emit an event, then on that event, you can use JS to click the toggle modal button and then call a method that will do the work you want to do.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Daramola Tunde |