Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bvfi-dev's avatar

Instant banner notifications not working without redirect

In my default app.blade.php I have:

<x-auth-session-status :status="session('status')" :isSuccess="session('isSuccess')" /> and from my components I pass:

return redirect('/profile')
    ->with('status', 'There was an error creating the Model. Error: ' .$e->getMessage())
    ->with('isSuccess', false);

This works with the redirect, however I made it now so that my Models are instantly updated, without a refresh. So, I dont want a redirect, as it takes the user to the top of the page. This was asked before here and here. I tried one solution where I return the view instead of a redirect, which didnt work:

session()->now('status', 'Addresse '. $action);
session()->now('isSuccess', true);
return view('livewire.address.addresses-management')

Tried session()->flash() as well, no avail. The dispatchBrowserEvent is deprecated, plus my banner component is custom, I dont use the banner component. What are the ways I can make it pop up, this is how my auth-session-status.blade.php starts:

@props(['status', 'isSuccess'])

@if ($status)
    @php
    $errorClass = $isSuccess ? ' bg-green-500 hover:bg-green-400' : ' bg-red-500 hover:bg-red-400';
    $icon = $isSuccess ?
    ...
0 likes
5 replies
ramonrietdijk's avatar

What exactly do you mean by "instantly updated"?

It seems like you are using Livewire, could you perhaps show in what function you are setting the session?

It's true that dispatchBrowserEvent is deprecated, but that's because it should be dispatch now. See the upgrade guide for more information.

bvfi-dev's avatar

@ramonrietdijk I have a livewire component called addresses management. The view is like:

<x-form-section submit="update">
    <x-label for="company_name" value="{{ __('Company Name') }}" />
    <x-input id="company_name" type="text"  wire:model="company_name"/>
    <x-input-error for="company_name" />
    ...
    <x-button wire:click="refreshComponent">
            {{ __('Save') }}
        </x-button>

So, in that view, when I press the save button it calls the refreshComponent and also triggers the update() function in my component:

class AddressesManagement extends Component
{
    protected $listeners = [
        'refresh-address-menu' => '$refresh',
    ];
    public function refreshComponent()
    {
        $this->dispatch('refresh-address-menu');
    }
    public function update()
    {
        try{
            $this->validate();
            $userId = Auth::user()->id;
            $address = Address::updateOrCreate(
                ['user_id' => $userId],
                $this->_getAddressData($userId), //Returns an array of entries to be filled it, works fine
            );

            $action = $address->wasRecentlyCreated ? 'erstellt' : 'aktualisiert';
            session()->now('status', 'Addresse '. $action);
            session()->now('isSuccess', true);

            return view('livewire.address.addresses-management')
                /*return redirect('/profile')
                    ->with('status', 'Addresse '. $action)
                    ->with('isSuccess', true)*/;
        } catch
    ...

So here, the refreshComponent is called when Save is pressed and it basically refreshes the component and then the update function updates my model correctly.

So, the page doesnt refresh, but the model is updated in the background. If I use the return redirect(/profile) part, then it displays a notification banner, but If I dont use redirect nothing shows up, but the model still gets updated. And I want to know how I can make it so that it instantly pops up a notification.

ramonrietdijk's avatar

I would highly recommend using wire:submit for this like documented by Livewire. Livewire does not use the returned view in the update method. Instead, it will re-render the view itself.

You should update your view with the following:

<x-form-section wire:submit="update">
...
<x-button type="submit">
    {{ __('Save') }}
</x-button>

And for the component, just keep the update method. You don't need the events and you don't have to return anything.

bvfi-dev's avatar

@ramonrietdijk Oh yeah, I probably should've mentioned that, but my form-section component has:

@props(['submit'])
<form wire:submit="{{ $submit }}">
...

I mean, at this point Im desperate and will take any solution, this isnt documented anywhere in Laravel and even less in Livewire, how I can display the notification instantly. You'd think they'd put some documentation over at this section, but no, they just use the redirect and Im not sure how I can figure it out. It just has a 4 sentence documentation about Flash messages.

ramonrietdijk's avatar
Level 30

By "instantly", you want to display a notification before the request to the back-end has finished? If so, you could make use of Alpine.js to show a notification, with x-show for example.

If not, the session should work and render the message.

Please or to participate in this conversation.