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

ycsm's avatar
Level 1

Props are not being passed to VueJS 3 from Laravel 10

Hi there. I have scoured the web and I can't see what I'm missing here...

I have a blade template index.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel='manifest' href='{{asset('manifest.webmanifest')}}'>
    <meta name="theme-color" content="#1f1d31"/>
    @vite('resources/css/app.css')
    <link rel="apple-touch-icon" sizes="76x76" href="/img/fav/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="/img/fav/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="/img/fav/favicon-16x16.png">
    <link rel="mask-icon" href="/img/fav/safari-pinned-tab.svg" color="#5bbad5">
    <meta name="msapplication-TileColor" content="#1f1d31">
    <meta name="theme-color" content="#ffffff">
    <title>Count Me In - Login</title>
    <style>
        body {
            background-color: #0093e9;
            background-image: linear-gradient(135deg,#0093e9,#80d0c7);
            background-attachment: fixed;
        }
    </style>
</head>
<body>
<div id="app">
    <App
        :user="{{auth()->user()}}"
        :hey="test1"
        there="test2"
    ></App>
</div>

@vite('resources/js/app.js')
</body>
</html>

As you can see, I am passing props (in three different ways) to a Vue component. Here is the App.vue:

<template>
    <v-app>
        <div @click="test()"><br><br><br><br>user: {{user}}<br>hey: {{hey}}<br>there: {{there}}</div>
        <v-app-bar app>
            Title
        </v-app-bar>
        <router-view/>
        <Snackbar></Snackbar>
    </v-app>
</template>


<script>

export default {
    props: {
        user: {
            type: Object,
            required: true
        },
        hey: {
            type: String,
            required: true
        },
        there: {
            type: String,
            required: true
        },
    },
    setup(props){
        console.log(props)
        //this.$store.dispatch('global/updateUser', this.user);
    },
    methods: {
        async test() {
            console.log(this.user)
        }
    },
}
</script>

Here is what I get:

page page2

Am I missing something completely obvious here?

EDIT: I have just tried passing a prop to a component FROM a component - it works. However, in this case, passing a prop from a BLADE file to a component isn't working...

0 likes
2 replies
JabatoForever's avatar

I think you could fix this problem by wrapping the variables in the @json directive but, as an alternative i would suggest you using inertia, with Inertia u have a section dedicated to shared props inside the middleware section, and components will get their props directly from the backend, so u will have your logged in user by default without the need of passing it directly to the app component in your blade.

<?php

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Inertia\Middleware;
use Tightenco\Ziggy\Ziggy;

class HandleInertiaRequests extends Middleware
{
    /**
     * The root template that is loaded on the first page visit.
     *
     * @var string
     */
    protected $rootView = 'app';

    /**
     * Determine the current asset version.
     */
    public function version(Request $request): string|null
    {
        return parent::version($request);
    }

    /**
     * Define the props that are shared by default.
     *
     * @return array<string, mixed>
     */
    public function share(Request $request): array
    {
        return array_merge(parent::share($request), [
            'auth' => [
                'user' => $request->user(),
            ],
            'flash' => function () use ($request) {
                return [
                    'success' => $request->session()->get('success'),
                ];
            },
            'ziggy' => function () use ($request) {
                return array_merge((new Ziggy)->toArray(), [
                    'location' => $request->url(),
                ]);
            },
        ]);
    }
}
ycsm's avatar
Level 1

Thanks! I will give that a go :) - for now I have just done an AJAX call

1 like

Please or to participate in this conversation.