laravel-splade icon indicating copy to clipboard operation
laravel-splade copied to clipboard

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

Open p4rad0xus opened this issue 3 months ago • 1 comments

  • Laravel Version: 10.46.0
  • PHP Version: 8.3.2
  • Splade JS Version (npm): 1.4.16
  • Splade PHP Version (composer): 1.4.16
  • Dev environment (OS, Sail/Valet/etc): Herd

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());
}

p4rad0xus avatar Mar 15 '24 09:03 p4rad0xus

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!');

dusp2k avatar Mar 17 '24 12:03 dusp2k