Close Modal bootstrap after saving changes?

I have an edit modal ( bootstrap ) everything is ok but I don’t find any event to close my modal after saving changes?

    <!-- Modal -->
    <div class="modal fade" id="editPost{{ $post->id }}">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                < :post="$post" :key="$post->id">

php code:

public $post; 
public $name;
public $desc;

public function mount($post)
    $this->post = $post;
    $this->name = $post->name;
    $this->desc = $post->desc;

public function editPost($id)

    $validatedData = $this->validate([
        'name' => 'required|unique:posts,name,'.$id,
        'desc' => 'required',

    session()->flash('message', 'Post successfully Added.');

Is there any event to close the modal in livewire?

If you can close the Bootstrap model using Javascript then you could listen for the livewire event and then close the modal using javascript. You would need to pass the postId with the event too:

 window.livewire.on('postUpdated', (postId) => {
     $('#editPost' + postId).modal('hide');

Your PHP would need to look like this:

$this->dispatchBrowserEvent('postUpdated', "$id");


I don’t use Bootstrap (I’m a Tailwind/AlpineJS convert :wink:) but the Livewire event system doesn’t dispatch the event as a JS window event.

You will need to create a listener in JS for a custom event that can then execute a callback that would toogle/hide the Bootstrap modal. Then in Livewire component use the $this->dispatchBrowserEvent('custom-event); method to dispatch the event on the JS window scope.

Here is some code I use with AlpineJs and Livewire:

Livewire component

class Create extends Component
    public $name = '';

    public function submit()
            'name' => 'required|unique:companies|min:3',

            'name' => $this->name,


    public function render()
        return view('');

Livewire view

<div x-data="{ open: false }" x-cloak class="relative">
        x-on:company-added.window="open = false"

            label="Company name"

        <button type="submit" class="focus:outline-none text-white py-2 px-4 rounded">
            <i class="fas fa-building"></i> {{ __('Create') }}
1 Like

Hi, brentvardy

Where should put this:

$this->dispatchBrowserEvent('postUpdated', "$id");

After editPost method or in the $listeners property?

In your PHP to replace: