wire-elements / modal

Livewire component that provides you with a modal that supports multiple child modals while maintaining state.
MIT License
1.09k stars 129 forks source link

404 on model deletion #405

Closed bjhfransen closed 6 months ago

bjhfransen commented 6 months ago

Creating and updating modals are working fine, but when I have a modal that asks for a confirmation to delete a given model I get a 404 and all modals are broken (all showing 404). I feel it's somewhere in the rehydration mechanics of the package. Tried to look into it and see if I could invoke the destroyComponent method and populate it with the activeComponent property. But to no avail. Went down in the inner workings of Livewire, events and hydration - but while I've learned a thing or two I din't find an answer there. I tried to comment of portions of logic, but also not the solution. Currently I'm down 8 hours trying to find clues in the inner workings of the package, but I ran out of ideas to tackle it. Thought it might be an issue.

Logic:

Issue:

Solution:

Image of confirmation modal

Schermafbeelding 2023-12-28 om 09 45 12

Image of the 404 happening (this happens to all elements that can call a modal; in my case for creating a new character, updating an existing one from the overview with cards, or deleting another one from the overview with cards)

Schermafbeelding 2023-12-28 om 09 45 20

From DeleteCharacter (modal)

public function delete()
    {
        if (!$this->authorized()) {
            abort(403);
        }

        $this->dispatch('characters-overview.delete', character: $this->character);

        $this->closeModal();
    }

From CharactersOverview (parent component, holding all the cards)

public function delete(Character $character)
    {
        if (!$this->authorized($character)) {
            abort(403);
        }

        if ($character->image) {
            Storage::disk('public')->delete($character->image->path);
            $character->image->delete();
        }

        $character->delete();

        $this->dispatch('characters-overview.show');
    }

From CharactersOverview too

#[On('characters-overview.show')]
    public function render()
    {
        $this->characters = Project::find($this->project->id)->characters()->get();

        return view('livewire.characters-overview');
    }