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

Breki's avatar
Level 4

Tighter Coupling between Laravel (PHP) and Vue (JS)

I've been building a fairly large project for the past year, starting as almost purely PHP-based backend coding, moving to Blade-based frontend work, and now moving to Vue. I've been migrating a lot of my Blade Views to Vue Single File Components...

During all of this, one of my major annoyances has been with how much work I'm having to repeat just to get the things that are already working in PHP => Blade to work in Vue... So I've been thinking - how much work has been done in developing tools and systems to better couple things from Laravel into Vue? There are several things that I can imagine being extremely useful but haven't been built yet (or which I haven't found, at least...) So I'm asking - does any of this exist today, and (if not) which of these things are most interesting to people out there to use once I sit down and start writing these extensions myself?

  • A way for components to "natively" export things directly to Vue.

... say something like return view('category.blog.index')->withVue(['articles' => $articles]);, which would be able to pass 'articles' in as a Vue component prop...

  • A way for Vue-Router to understand Laravel's route definitions.

... maybe adding notation/syntax to Laravel's route files so that Vue-Router doesn't need any configuration files of its own...

  • Eloquent in Vue

... This is a big one, of course, but shouldn't be too difficult if one is okay with this being done server-side in a separate process. Would reduce the need for APIs and Axios and VueX for so many of the 'smaller' things we do.

  • Javascript (Node) jobs in Laravel's job worker

... Again, not too difficult if you're okay with something like $schedule->exec('node /var/www/scripts/maint/backup.js')->daily();, but a tighter integration should be possible...

... These are just a handful of examples that I've been thinking about of late, but something that I believe would come in very handy for people wanting to implement Vue (or expand Vue's presence on their site) but who don't have much Javascript experience... What do you think?

0 likes
5 replies
primordial's avatar

In general, the idea is to decouple these solutions not the other way around. Perhaps you could write a package (npm/composer) to meet your needs.

Breki's avatar
Level 4

Sure, anything I build for this would by definition be an optional package; nothing that I would suggest merging into Laravel or Vue. :) I'm mostly just thinking of adding conveniences where the Laravel <-> Vue communication is being made more difficult than it has to be.

rawilk's avatar

say something like return view('category.blog.index')->withVue(['articles' => $articles]);, which would be able to pass 'articles' in as a Vue component prop...

You can already pass in data from php to vue as a prop:

<articles :articles="{{ json_encode($articles) }}"></articles>
1 like
Robstar's avatar

@WILK_RANDALL - Or using the json Blade tag :)

<articles :articles="@json($articles)"></articles>
1 like
cmdobueno's avatar

Or if it is a collection, without json. Yay for collections!

Additionally, this seems like too much, at least to me.

I want my PHP BACKEND to be decoupled from VueJS frontend. I have at times gone as far as creating two totally different frontends for this. Reason being? I want to know that, in the end, my 'api' is totally stand alone. I want to be able to upgrade my UI/UX at ANY time, with 0 impact on the system.

I can keep the system running no matter how frontend technology is improved. For when the next cool thing comes out (you know like vuejs, angular, react... who knows whats really next).

I know that PHP will grow as will laravel, but I am not using ground breaking things. Honestly my API has been following as simple of a base as possible. I do not want overly complicated things running this thing.

If, (big if), I do this correctly, this app should survive with me having to do very little to the php code (future optimization, and additional features). While I can re-write the frontend every 1-2 years depending on need.

Please or to participate in this conversation.