[Vuejs]-Inertia Responses

0👍

Unfortunately, there’s no direct way. It can be done in this hacky way, though.

Change your App\Http\Middleware\HandleInertiaRequests middleware to have a data key in Shared data

public function share(Request $request): array
{
    return array_merge(parent::share($request), [
        'auth.user' => \Auth::user(),
        'flash' => [
            'error' => fn () => $request->session()->get('error'),
            'success' => fn () => $request->session()->get('success'),
            'data' => fn () => $request->session()->get('data') // add this line
        ],
    ]);
}

While processing your request on the server side, you can do something like this:

public function submitTagForm()
{
    // process form data

    return redirect()->back()
        ->with('success', 'Settings saved successfully')
        ->with('data', ["one"=> "one", "two"=> "two"]); // add this extra line to pass desired data
}

Finally, in your Inertia.Js code, you can simply access any data passed:

addTag.post('tags', {
    preserveScroll: true,
    resetOnSuccess: false,
    onSuccess: (response) => {
        console.log(response.props.flash.data);
    }
})

0👍

Just use tagForm, You can handle it on front side.

> let addTag = () => {
>     tagForm.post('/tags', {
>         preserveScroll: true,
>         resetOnSuccess: false,
>         onSuccess: () => this.tagForm   // you can access form here as well user input >Tag .
>     }) };

Leave a comment