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

Lowelheim's avatar

[Laravel 12 + Vite + BS5] Having problem with the Vite refresh

Good day fellows, I appeal to those in the forum that got more knowledge about Laravel.

I started a new project with Laravel 12, Vite and Bootstrap 5 and things went smooth, at least for what about the DB code first and basic front end layout, authentication and so on.

I've started working seriously on the backend to implement all the business logic and so on and I started to experience something I never experienced before with Laravel + Vite: when I change something within the code behind, thus in the backend, there's no way to reflect the changes in the browser (not even running artisan command for optimize) and most of the time I need to restart Vite, which is very annoying.

I tried to figure out by myself what's wrong with my config, but so far I did not really find any difference between this project and the others done with Vite and honestly, since I am former .NET programmer, I lack some precious knowledge and I am not sure if it's something within the Laravel's config or else.

My Vite config is standard.

Any good advice where could I search for more clues?

Kind regards

0 likes
2 replies
LaryAI's avatar
Level 58

Certainly! This behavior is expected with Vite: Vite’s hot module replacement (HMR) and auto-refresh only trigger when frontend source files change (like JS, Vue/React/Blade, or CSS), not when backend PHP code changes. That's why, when editing purely backend logic (controllers, models, routes, etc.), Vite doesn’t know to refresh—it's not designed to watch PHP files.

Here’s what you can do:

1. Use Laravel’s vite-plugin-laravel (Optional)

There are community plugins, like vite-plugin-laravel, which support refreshing the browser when PHP files are modified. Consider using one for your dev environment:

Install the plugin:

npm install vite-plugin-laravel --save-dev

Update your vite.config.js:

import { defineConfig } from 'vite';
import laravel from 'vite-plugin-laravel';

export default defineConfig({
    plugins: [
        laravel()
    ],
});

Now, changes in Blade/PHP files will also trigger a reload.


2. Manual Browser Extension ("LiveReload")

Use a browser extension like LiveReload or BrowserSync, which can be configured to watch your PHP files and refresh the browser on changes.

Example with BrowserSync and Laravel Mix:
If you previously worked with Laravel Mix, it offers built-in BrowserSync support, which can be adapted for pure frontend workflows, but it doesn't fit well when exclusively using Vite.


3. Hybrid Approach: Manual Refresh

For many teams, the accepted workflow is to manually refresh the browser after backend changes. This is what most Laravel + Vite projects do, since most backend code doesn’t affect the frontend rendering until the next request.


4. Check For Caching Issues

Sometimes not seeing backend changes reflects caching (Laravel cache, route cache, view cache, etc.).

  • Clear Laravel cache:
    php artisan cache:clear
    php artisan config:clear
    php artisan view:clear
    php artisan route:clear
    

This ensures you’re seeing the latest backend changes.


Summary Table

Change Type Vite Auto-Refresh? Solution
JS/CSS/Blade change Yes Vite HMR
PHP (backend) change No Manual reload, LiveReload, plugin

Conclusion

You’re not missing config—this is standard with Vite and Laravel.
For auto-refreshing on backend changes, consider vite-plugin-laravel or a LiveReload solution. Otherwise, refresh the browser when updating backend code.

Let me know if you want an example of a full setup with vite-plugin-laravel!

gotham337's avatar

Hi Lowelheim,

What you’re experiencing is actually a common situation with Laravel + Vite. Vite primarily watches frontend assets (JS, CSS, Vue/React components) for hot reload. Changes in backend PHP code (controllers, models, routes) won’t automatically trigger a browser refresh — that’s why you often have to restart Vite or refresh manually.

A few tips:

Use Laravel’s built-in auto-refresh for backend changes:

Vite won’t watch PHP files. To see backend changes, just reload the browser manually or use a package like spatie/laravel-web-tinker or barryvdh/laravel-debugbar to make debugging faster.

Optional: Laravel Mix style HMR for PHP

Some devs use Browsersync or Livewire + Vite to auto-refresh the browser on backend changes.

Check caching & config:

Run php artisan config:clear and php artisan route:clear to ensure no cached config is blocking updates.

Basically, Vite hot reload is frontend-focused, and backend changes require a manual refresh. If you want full auto-refresh on PHP changes, adding a small watcher or using Livewire with vite can help.

Please or to participate in this conversation.