How to pass a PHP variable to Vue component instance in Laravel blade?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: An Efficient Method for Passing PHP Variables to Vue Components in Laravel Blade Introduction: In modern web applications, using both PHP with Laravel framework and JavaScript with Vue.js can be a powerful combination. However, efficiently passing data between these two languages can sometimes prove challenging due to their distinct syntaxes. In this blog post, we will guide you through the process of successfully passing a PHP variable to a Vue component instance in Laravel blade files using best practices. Step 1: Declare the PHP Variable in the Controller or Blade File Firstly, you need to declare the PHP variable containing the value you want to pass to your Vue component. For example, if you are working in a controller and wish to pass the user's 'clientId' as an integer from the URL /client/1:
route('id');
?>
Step 2: Use Laravel Blade to Create Client-Details Component Now that you have the PHP variable, you need to create a Vue component for your HTML template. In Blade, firstly define an inline template tag containing the client-details component:
<client-details inline-template>
    <div id="client-details" class="">
          My HTML stuff
    </div>
</client-details>
Step 3: Define the ClientDetails Vue Component in the App.js File Next, you should define the ClientDetails Vue component using JavaScript within your app.js file:
Vue.component('client-details', {
    data(){
        return {
            clientId: null
        }
    },
    mounted() {
        // Retrieve the PHP variable value from Laravel Blade
        this.clientId = ;
    },
});
Here, we are adding a 'mounted' method to the component that can fetch and assign the PHP variable value to the 'clientId' data property when the component instance is created. Step 4: Pass the PHP Variable to the Vue Component Instance in Laravel Blade Finally, you need to pass the 'client_id' variable from your controller or Blade file to the 'data()' method inside the Vue component using the correct syntax:
route('id');
?>
<client-details inline-template data="{ clientId:  }">
    <div id="client-details" class="">
          My HTML stuff
    </div>
</client-details>
This code snippet uses the PHP echo function to interpolate the value of '$clientId' into the 'data()' method inside the Vue component. This ensures that your Vue component instance has access to this critical piece of data, enabling you to use it within your HTML template as needed. Conclusion: The process of successfully passing a PHP variable from Laravel blade files to a Vue component is relatively straightforward if implemented correctly. Always remember to keep your code well-organized and clearly structured so that understanding the logic behind each step is simple. By following these steps, you can confidently leverage the power of both PHP with Laravel and JavaScript with Vue for greater efficiency in your web applications.