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

kevinwakhisi's avatar

Access methods from model vue

Using laravel's blade i can easily call a method from the model and i have been trying to make this possible in vue js could anyone shed light to this.

<kbd>{{ $invitation->getLink() }}</kbd>

Above was how i got the string using laravel blade.

And below is method inside the model

 	 /**
     * @return string
     */
    public function getLink()
    {
        return urldecode(route('register') . '?invitation_token=' . $this->invitation_token);
    }

But i need help displaying the string in vue data

0 likes
1 reply
martinbean's avatar

@kevinwakhisi Your models (and views) are server-side. Vue is client-side. You can’t call PHP code from JavaScript. The PHP process has been and gone by the time a single line of JavaScript is executed in a page load.

So, pass the link as a prop from your Blade view to your Vue component:

// Pass invitation link to view
return view('some-view', [
    'invitationLink' => $invitation->getLink(),
]);
<!-- Pass invitation link from view to Vue component as a prop -->
<foo-component invitation-url="{{ $invitationLink }}"></foo-component>
<!-- Alternatively, pass $invitation to view and call method on it -->
<foo-component invitation-url="{{ $invitation->getLink() }}"></foo-component>

Please or to participate in this conversation.