protonemedia / laravel-splade

💫 The magic of Inertia.js with the simplicity of Blade 💫 - Splade provides a super easy way to build Single Page Applications (SPA) using standard Laravel Blade templates, and sparkle it to make it interactive. All without ever leaving Blade.
https://splade.dev
MIT License
1.47k stars 109 forks source link

x-splade-flash doesn't show Flash-Data #555

Open p4rad0xus opened 6 months ago

p4rad0xus commented 6 months ago

Description:

On a Blade-Plage I want to show a Flash-Message after submitting a form. To do this I use the x-splade-flash component and generate in the controller the flash data. The form is a x-splade-form component and there I want to use the some options like stay, reset-on-success and @success.

If I don't use the option stay it shows me only the flash data over the session() method. If I use the option stay in the form component neither the x-splade-flash component nor the session() method shows the data.

Steps To Reproduce Issue:

My Blade-File

<x-splade-flash>
    <p v-if="flash.has('message')" v-text="flash.message" />
</x-splade-flash>

@if(session('message'))
    <div class="alert alert-success">
        {{ session('message') }}
     </div>
@endif

<x-splade-form action="{{ route('information.store') }}"
                            stay
                            reset-on-success
                            @success="$splade.emit('information-added')">
   ....
   <x-splade-submit label="Submit" />
</x-splade-form>

<x-splade-rehydrate on="information-added">
    <x-splade-table :for="$informations">
        ...
     </x-splade-table>
</x-splade-rehydrate>

My Controller - store-Method

public function store(Request $request)
{
        ....

        $request->session()->flash('message', "Some data");

        return redirect($request->getRequestUri());
}
dusp2k commented 6 months ago

It seems to be working if you save the session manually.

public function store(Request $request): RedirectResponse
{
        ....

        $request->session()->flash('message', "Some data");
        $request->session()->save();

        return back();
}

You can also use a Toast:

Toast::success('Saved successfully!');