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

matask's avatar

Laravel PHP code in Vue Components

Hello,

So I was thinking it would be useful if I could use Laravel code, like helper functions, inside Vue Components but can't come up with a good solution. The only way to do this in my mind would be to send an Http request with a string which the PHP in the Controller then would eval() and run actual code that you want it to and return a response, but then anyone could run such code on a server so this is not a good solution.

There needs to be some way for the server to check if this request is coming from a feature implemented by the developer and not from a user or anyone else. The simplest way would be to code different paths for different helpers but maybe it's possible to do this so I could run any code with just one path and one method?

Thanks

0 likes
1 reply
jlrdw's avatar

You can have php in javascript, example from jquery

url: '<?php echo DIR . "owner/getowner"; ?>',

vue is javascript. I'd suggest a google search for more information.

Please or to participate in this conversation.