@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.