Issue with Laravel Jetstream + Inertia: Flash message not showing up after redirecting to the same page

I'm currently facing a problem with displaying flash messages in my Laravel Jetstream application using Inertia.js. Below is the relevant code snippet: In AppLayout.vue

<script setup>
import { usePage } from "@inertiajs/vue3";
import FlashMessage from "../Components/FlashMessage.vue";
import { ref, computed, onMounted } from "vue";

const { props: pageProps } = usePage();
const flashMessage = ref("");

const successMessage = computed(() => pageProps.flash.success);

onMounted(() => {
    if (successMessage.value) {
        flashMessage.value = successMessage.value;
    }
});
</script>

<div class="bg-white w-full shadow relative lg:fixed lg:top-0 z-50">
    <FlashMessage :success="flashMessage" />
</div>

Within the handleInertiaRequest method:

public function share(Request $request): array
{
    return array_merge(parent::share($request), [
        'flash' => function () use ($request) {
            return [
                'success' => $request->session()->get('success'),
                'error' => $request->session()->get('error'),
            ];
        },
    ]);
}

Inside ClaseController:

public function destroy($id)
{
    $clase = Clase::find($id);

    $clase->delete();

    return redirect()->back()->with('success', 'Clase Eliminada Exitosamente');
}

Most aspects appear to be functioning correctly except for when the flash message redirects to the same page. It seems that the pageProps variable isn't capturing the message, even though it is received as evident by {{$page.props.flash.success}} appearing on screen when printed.

What could potentially be causing this particular issue? Your assistance would be highly appreciated!

Answer №1

Is it possible to view the frontend request? If you utilized only, make sure to also request flash.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The issue at hand is the lack of execution for the Mocha Chai `.end()`

I have encountered an issue while trying to write a Mocha chai test for a Nodejs API that was previously tested using Supertest. Strangely, the test always passes even when I intentionally specify wrong expected parameters. Below is the code snippet of th ...

How to display an unordered list horizontally in HTML

I'm working on a screen that has filters displayed vertically, but I want to align them horizontally and have the filter options arranged in two columns. I've tried using CSS properties like spacing, clear, and display block, but the checkboxes/l ...

Encountering difficulties reading data from a database in a Next.js/Firebase application

I am encountering a problem within a nextJS app that I developed on Firebase. In my realtime DB, I have some stored data that I want to read using a component. Below is my firebase/config.js file: import {initializeApp} from "firebase/app"; imp ...

Encountering a javascript error when clicking on an Ajax link?

Within my partial view, I have included an ajax action link: @foreach (var times in Model.ProvidedDateTimes) { <tr> <td> @times.StartDateTime &nbsp; to &nbsp; @times.EndDateTime </td> <t ...

An uncommon symbol has been encountered - it is possible that you require a suitable loader in order to manage this particular file format

Hey there, I need some help with importing the javascript strapi sdk (link) into my new project that is configured using webpack. Here's what I have so far: index.ts file import * as $ from 'jquery'; import Strapi from 'strapi-sdk-ja ...

Shortcut to prevent false 0 values

When my server responds, it sends back an object structured as follows: { success: integer } Meanwhile, on the client side I'm using: return body && body.success; The issue arises when the integer is zero, causing the above code to return ...

Content briefly appears and then vanishes with the use of ng-if

On my webpage, I have content that is enclosed in an ng-if directive as shown below: <div ng-if="ShowMessgae" class="text-danger"> <p> <strong> Message displayed to User </strong> </p> < ...

Chrome is having trouble setting the cookie with the Set-Cookie header

I am making an AJAX call to another service's API, expecting to receive a cookie that will be stored in my browser for future API calls. Unfortunately, even though the response headers contain a 'Set-Cookie' header, the cookie is not being s ...

Vue CLI service does not generate CSS files when using the 'watch' command during the build

My project was created using vue-cli and I am facing an issue with CSS file generation. When I use the command vue-cli-service build, the CSS file is generated correctly. However, when I run the command vue-cli-service build --watch, only JavaScript files ...

Manipulating the renderer component attributes within the <a-scene> tag

Here is a snippet of code in A-Frame that I'm currently working with. My goal is to access and modify the maxCanvasWidth and maxCanvasHeight properties of the renderer component using JavaScript conditional statements, but I'm struggling to figur ...

What could be the reason for jQuery not functioning properly as needed?

function toggleDisplayingRooms(nameSelect){ if(nameSelect){ firstroom = document.getElementById("firstroom").value; secondroom = document.getElementById("secondroom").value; thirdroom = ...

Looking for a drum set with clickable buttons? Having trouble changing the background color in CSS/HTML? Wondering how to map keyboard keys to HTML buttons?

Behold my HTML creation: <H1> <center> EPIC GUITAR JAM </center> </H1> <img class="guitar" src="guitar.jpg" /> <button class="strum" onclick="Strum()"> Strum Chord </button> <button class="pluck" o ...

Interactive tooltip feature in Apexchart

I need to include % in my Apexcharts tooltip after the Y value. Working with vue.js and without official documentation from apexchart, I managed to make it function correctly. This is what I have accomplished so far: data: function () { return { ...

Activate jQuery after a vanilla JavaScript function has been executed

I have created a jQuery function that captures any changes made to an input field and stores them in a variable. The input field is connected to a vanilla JavaScript based API library, which I am unable to convert to jQuery. This library is for an address ...

Live monitor database changes with AJAX and SQL technology

Is there a way to implement real-time updating of user ratings on comments in an application with a connected database? I've explored various sources but the responses have been inconsistent and inconclusive. I am currently creating an app where user ...

Is CakePHP unable to handle multiple Ajax requests simultaneously?

After multiple rounds of editing this post, I keep uncovering new information through testing and debugging. Here is my current situation: I have a method thinker that takes a significant amount of time to process. To address this, I have decided to call ...

Removing selected options from multiple select boxes in AngularJS using ng-repeat

When using ng-repeat to load multiple select dropdown elements, each dropdown contains the same set of values. However, when a user selects an option from one select box, that option should not appear in any of the other select boxes. For example, if a us ...

Unable to create a flawless circle using Canvas

No matter how hard I try, drawing a perfect circle seems impossible for me. Every time I attempt it, all I manage to create is an ellipse. Check out this code snippet I put together as an example: function canvasClicked(number) { var c = "canvas" + nu ...

Ways to prevent event bubbling in the case of a checkbox input alteration?

Description I am looking to create a table component with checkboxes, but I am facing an issue. Whenever I click on a checkbox, the click event is also triggered for the table row and cell containing the checkbox, which is not what I want. I have tried us ...

The references to the differential loading script in index.html vary between running ng serve versus ng build

After the upgrade to Angular 8, I encountered a problem where ng build was generating an index.html file that supported differential loading. However, when using ng serve, it produced a different index.html with references to only some 'es5' scri ...