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

Iljido's avatar

subscribe button not working returning Function name must be a string

hi well again in build forum tutorial (episode 43 : thread subscription) , when i put this line in show.blade.php

<subscribe-button :active="{{  json_encode($thread->isSubscribedTo) }}"></subscribe-button>

it shows me this error : Function name must be a string (it show when i try to click on a thread )

here's the subscribeButton.vue :

<template>
    <button :class="classes"  @click="subscribe">Subscribe</button>
</template>

<script>

    export default {

        props: ['active'],

        computed: {

            classes(){
                return ['btn' , this.active ? 'btn-primary' : 'btn-outline-primary'];
            }
        },
        methods: {
            subscribe(){

                axios[(this.active ? 'delete' : 'post')](location.pathname + '/subscriptions');

                this.active = ! this.active;


            }
        }
    }
</script>

thanks for reply

0 likes
2 replies
James_Moore's avatar
Level 14

Hey @iljido I wasnt able to replicate your error but what you have on your component looks correct. I've had issues with the json_encode helper in the past, but if its a show route and your only showing a specific thread not looping over several threads.

in the controller that supplies the thread variable try this

Controller

    public function test()
    {
        $thread = new RandomThing();

        $isThreadSubscribedTo = $thread->isSubscribedTo;

        return view('test', compact('isThreadSubscribedTo'));
    }

Component

<template>
    <button :class="classes"  @click="subscribe">Subscribe</button>
</template>

<script>
    import axios from 'axios';

    export default {


        props: ['active'],

        computed: {

            classes(){
                return ['btn' , this.active ? 'btn-primary' : 'btn-outline-primary'];
            }
        },
        methods: {
            subscribe(){
                // axios[(this.active ? 'delete' : 'post')](location.pathname + '/subscriptions');
                console.log(this.active);
                this.active = ! this.active;
            }
        }
    }
</script>

check your console and see what its spitting out, is a boolean value if so this could be a temporary solution till you figure out whats wrong with your json encode syntax I believe json_encode calls typically look like this and it bundles it up the array like a object, key => value

echo json_encode([
    'status' => 'success',
    'data' => $data,
]);
1 like

Please or to participate in this conversation.