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

claybitner's avatar

Trying to get property from Controller to Blade to Vue

I have created a new page (not dissimilar to the default settings page) where I have listed details of a users's household. I am trying to get the properties of 'person', 'user', and 'household' into the Vue component but receive the error, Property or method "household" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. among similar errors referencing missing 'person' as well.

This is what my household-details.blade.php contains:

<household-details :user="user" :household="household" :person="person" inline-template>
...
<form role="form">
...
                        <input type="text" class="form-control" name="name" v-model="form.name" :class="{'is-invalid': form.errors.has('name')}">
</form>
...
</household-details>

This is what is inside my household-details.js contains:

var base = module.exports = {
    props: ['user', 'person', 'household'],

    /**
     * The component's data.
     */
    data() {
        return {
            form: new SparkForm({
                name: '',
                legal_name: '',
            })
        };
    },


    /**
     * Bootstrap the component.
     */
    mounted() {
        this.form.name = this.household.name;
        this.form.legal_name = this.household.legal_name;
    },


    methods: {
        /**
         * Update the user's contact information.
         */
        update() {
            Spark.put('/settings/household', this.form)
                .then(() => {
                    Bus.$emit('updateHousehold');
                });
        }
    }
};

Vue.component('household-details', {
    mixins: [base]
});

And finally, my controller has this:

class SettingsHouseholdController extends Controller {
    public function __construct() {
        $this->middleware('auth');
    }
    public function index(Request $request) {
        $user = Auth::user();
        $person = $user->getPerson($user->currentTeam->id);
        $household = $person->household();
        return view('settings.household.household', ['household' => $household, 'person' => $person, 'user' => $user]);
    }
}

I can't figure out what I'm missing.

Am I going about this all wrong? I'm trying to copy how spark does its 'update-contact-information' page, but this is all I find in the js:

var base = require('settings/profile/update-contact-information');

Vue.component('spark-update-contact-information', {
    mixins: [base]
});

I can't figure out where that base require is even coming from.

Any help appreciated.

0 likes
3 replies
bryanmonzon's avatar

With Spark, if you look in the app.blade.php layout, you'll see they're setting up a global javascript object. This is why you see the v-bind shortcut in use `:user="user".

When you're passing it in from PHP, you need to drop the colon and pass in the variable like this.

<household-details :user="user" household="{{ json_encode($household) }}" person=" json_encode($person)}}" inline-template>

All of the base vue stuff from spark is in the spark/resources/assets/js/... folder.

Hope this helps!

claybitner's avatar

Thanks @bryanmonzon! That's a great start.

The only issue now is that when I inspect the details of the "household" var inside the js, it's only showing the json, and it's not transforming it into a js object. Any extra clues?

bryanmonzon's avatar

Sorry for the super delayed response. You need to use JSON.parse() or to get the object.

Please or to participate in this conversation.