JeroenvanRensen
4 months ago
417
3
Vue

Laravel Vue - v-bind only works if logged in

Posted 4 months ago by JeroenvanRensen

Hi everyone,

I'm creating a forum with Laravel and I've got the following problem:

If I'm logged in in the browser, it totally works. But if I go to a private window, I got the following message:

Method Illuminate\Database\Eloquent\Collection::__toString() must not throw an exception, caught ErrorException: Trying to get property 'id' of non-object 

Does anyone know what to do?

Thank you! Jeroen

If you need more information, please ask me.

Here's the resources\views\threads\show.blade.php file, where I'm calling the replies component:

<replies :data="{{ $replies }}" @removed="repliesCount--"></replies>

And here's the Replies.vue component:

<template>
    <div>
        <new-reply @created="add"></new-reply>

        <div v-for="(reply, index) in items">
            <reply :data="reply" @deleted="remove(index)"></reply>
        </div>
    </div>
</template>

<script>
    import Reply from './Reply.vue';
    import NewReply from './NewReply.vue';

    export default {
        props: [
            'data'
        ],
        
        components: { Reply, NewReply },

        data() {
            return {
                items: this.data
            }
        },

        methods: {
            add(reply) {
                this.items.push(reply);
            },

            remove(index) {
                this.items.splice(index, 1);

                this.$emit('removed');

                toast('Your reply has been deleted!');
            }
        }
    }
</script>

Please sign in or create an account to participate in this conversation.