Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TylerW's avatar

Variables From Laravel Session To Vue

I know there are other threads created about this, but I've been scouring them for over an hour and I cannot seem to understand how to achieve the desired functionality I want.

I have a text input bound to "hand", a data property in my Vue instance. This is set to blank by default. There is a button next to the input with an @click="lastHand", which calls a Vue method that is supposed change the hand property to the value of session->get('last_hand').

Here is my Vue code, which references the problem:

const app = new Vue({
    el: '#app',
    data: {
        hand: ''
    },
    methods: {
        lastHand() {
            this.hand = "This string should be equal to session()->get('last_hand'), how do I put that here?"
        }
    }
});
0 likes
2 replies
balistikbill's avatar

You would have to pass that session()->get('last_hand') as a prop.

usaandi's avatar

@TylerW That should do the trick?

const app = new Vue({
    props:{
    lastHand: {}
    },
    el: '#app',
    data: {
        hand: this.lastHand
    },
 
    }
});

Passing data from blade view

<div id="app">
<my-template :last-hand={{json_encode(session()->get('last_hand'))}}> </my-template>
</div>

Please or to participate in this conversation.