0

I am making a simple CRUD with Laravel, Inertia and Vue... All functionalities work fine, but on delete the flash message doesn't work well.

I follow the documentation and all the others functionalities work perfectly, but the delete doesn't show the flash message.

1
  • Please provide enough code so others can better understand or reproduce the problem. Commented Nov 28, 2023 at 8:43

1 Answer 1

0
// Laravel code
class HandleInertiaRequests extends Middleware
{
    public function share(Request $request)
    {
        return array_merge(parent::share($request), [
            'flash' => [
                'message' => fn () => $request->session()->get('message')
            ],
        ]);
    }
}

// vue3 code
<template>
  <main>
    <header></header>
    <content>
      <div v-if="$page.props.flash.message" class="alert">
        {{ $page.props.flash.message }}
      </div>
      <slot />
    </content>
    <footer></footer>
  </main>
</template>

{{ $page.props.flash.message }} will work in template, If you want to get message in strip so you has to follow the below code.

import {usePage} from '@inertiajs/vue3'

const message = usePage().props.flash.message;

You can get anything from usePage() or $page in template if you have shared it in middleware HandleInertiaRequests.

Add dd() in HandleInertiaRequests and sure that message is available here or not.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.