masmerise / livewire-toaster

Beautiful toast notifications for Laravel / Livewire.
MIT License
342 stars 22 forks source link

Toasts is not showing after livewire redirect from component #19

Closed bee-interactive closed 9 months ago

bee-interactive commented 10 months ago

Hi!

I have some issue to show the toasts after a redirect from a Livewire component. I'm assuming it's because of the redirect but as explain is the readme, it should work.

Here's my actual configuration:

Laravel version: 10.20 PHP version: 8.2 Livewire version 3.0 Toaster version: 2.0

Here's the save method inside my Livewire component:

public function save()
{
    $category = Category::create($this->validate());

    return redirect()->to(route('home'))->success(__('Your category has been created'));
}

The rest of the component is only a mount method and some validation rules.

I have tried different approaches inside the save method too:

return redirect(route('home')->success(__('Your category has been created'));
Toaster::success(__('Your category has been created'));

return redirect(route('home');

I have added the Toast package successfully since I can make it work in other components without the redirect (send toast after a modal close event for exemple)

Any ideas were I miss something?

Thanks in advance!

mabdullahsari commented 10 months ago

Can you please read this issue thoroughly, go through each step and report back with your findings? Thanks.

bee-interactive commented 10 months ago

Hi! Thanks for the feedback.

I have tried with the redirect response, still the same result. I don't have any errors, it just redirects me to the page but no toasts is showned.

Another thing I forgot to mention is that the Component is a ModalComponent, used from the wire-elements/modal package. Maybe a conflict with this one?

mabdullahsari commented 10 months ago

@bee-interactive I don't think so.

bee-interactive commented 10 months ago

Yes everything is correctly set up. I use the toasts in other parts of the application and it's working fine. Except the parts were I redirect the user after an action.. Strange

mabdullahsari commented 10 months ago

Could you verify that the ModalComponent is not the culprit here? Are you redirecting in a non-modal component, ie. standard component elsewhere?

bee-interactive commented 10 months ago

I'm simply redirecting to the home page. No components on the homepage..

mabdullahsari commented 10 months ago

Sure, but where you are redirecting from is equally important. That's my question 👍

bee-interactive commented 10 months ago

Sorry :-)

I have the same behavior within a standard controller. After the save, the user is redirected but no toasts is shown.

Here's the update method inside a basic Laravel controller:

public function update(EventUpdateRequest $request, Event $event): RedirectResponse
{
    $event->update($request->validated());

    return Redirect::route('home')->info(__('The informations have been updated'));
}
mabdullahsari commented 10 months ago

Redirects are handled using the active user session, so please double check if it's set up correctly. Non-redirecting action toasts do not use the session (that's why it works).

If everything looks fine... could you please provide a minimal reproduction repository that I can use in order to track down the cause of this issue? Thanks!

mabdullahsari commented 10 months ago

Hi @bee-interactive

Is there any link I could use? Thanks a lot.

bee-interactive commented 10 months ago

@mabdullahsari Hi! I will prepare a test repository!

mabdullahsari commented 9 months ago

Hi @bee-interactive

Any news on your test repository?

bee-interactive commented 9 months ago

@mabdullahsari Hi! Sorry for the late response. It turns out upgrading my Laravel application and upgrading to the latest version of Livewire fixed the issue.