How to pass boolean values from Blade to Vue Component Laravel 7?

Stefan Bogdanescu

Founder & Senior Architect · 2026-06-29

Laravel Company

How to Pass Boolean Values from Blade to Vue Component in Laravel 7: A Complete Guide

As developers working with the Laravel and Vue ecosystem, bridging the gap between server-side logic (PHP/Blade) and client-side reactivity (Vue) often involves subtle type mismatches. One of the most common stumbling blocks is correctly passing boolean values—true/false—from your Laravel controller through Blade to a Vue component so that directives like v-if function reliably.

If you are trying to implement conditional rendering based on a boolean flag, and you find that even when debugging confirms the value is true, the Vue component's logic fails, it usually points to an issue with data serialization or type coercion between the PHP environment and the JavaScript environment.

This guide will walk you through the most robust and idiomatic ways to pass boolean values from your Laravel backend to a Vue component, ensuring your conditional logic works flawlessly.

The Pitfall: Type Mismatches in Data Transfer

The issue you are encountering often stems from how data is serialized. When Blade outputs data, it converts PHP types (like booleans or integers) into strings for injection into the HTML. If you rely on string comparisons ('1' vs true), inconsistencies arise, especially when dealing with strict JavaScript type checking in Vue.

For instance, comparing a string '1' to a boolean true will always fail unless you explicitly handle the conversion. Relying on numeric strings like "1" or "0" is sometimes safer than relying purely on Booleans if the backend logic naturally outputs integers, but we need consistency.

Solution 1: Passing Native Booleans Directly (The Best Practice)

The cleanest approach is to ensure that your Laravel data is already a native PHP boolean (true or false) and let Eloquent/Blade handle the final output conversion. Vue components natively understand JavaScript booleans, making this the most readable solution.

Step 1: Ensure Backend Data is Boolean

Make sure your controller explicitly returns a boolean value.

// In your Laravel Controller method
public function showQuiz(Request $request)
{
    $isExamAssigned = $request->input('exam_assigned', false); // Defaults to false if not present
    return view('quiz.index', ['isExamAssigned' => $isExamAssigned]);
}

Step 2: Pass the Boolean to Blade and Vue

In your Blade file, pass this variable directly using the : syntax for binding.

Blade File (.blade.php):

<quiz-component
    :isExamAssigned="$isExamAssigned"
>
</quiz-component>

Step 3: Consume in the Vue Component

In your Vue component, you receive this as a native boolean prop. You can use it directly in v-if.

Component File (.vue):

<template>
  <div>
    <div v-if="isExamAssigned">
      <h2>Exam Assigned! Proceed to quiz.</h2>
    </div>
    <div v-else>
      <p>Please complete the assignment first.</p>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    isExamAssigned: {
      type: Boolean, // Explicitly define it as a boolean prop
      required: true
    }
  },
  // No need for complex data() setup if you are only consuming props
}
</script>

Solution 2: Handling Integer/String Values (If Necessary)

If your backend logic must return 1 or 0 (perhaps due to database constraints), you can still use this, but you must ensure Vue interprets it correctly. Since we established that 1 is truthy and 0 is falsy in JavaScript, direct comparison works well if the data is numeric.

Blade File:

<quiz-component :isExamAssigned="{{ $isExamAssigned ? 'true' : 'false' }}">
</quiz-component>

Note: While this forces a string output, it keeps the structure predictable.

Component File (Using Numeric Comparison):
You can safely compare against the number 1 or 0.

<template>
  <div>
    <!-- Check if the prop is strictly equal to the number 1 -->
    <div v-if="isExamAssigned === 1">
      <h2>Exam Assigned (Numeric Check)!</h2>
    </div>
    <div v-else>
      <p>Status unknown.</p>
    </div>
  </div>
</template>

<script>
export default {
  props: ['isExamAssigned'],
  // isExamAssigned will be the number 1 or 0 passed from Blade
}
</script>

Conclusion and Best Practices

For modern Laravel and Vue applications, Solution 1 (Passing Native Booleans) is highly recommended. It promotes cleaner code, avoids type coercion headaches, and aligns better with the principles of reactive programming by using native JavaScript boolean logic directly within your templates.

When building robust applications on top of Laravel, always strive to send the most semantically correct data types from the server to the client. If you are looking for deeper insights into how Laravel structures its data and best practices for API design, exploring resources like Laravel Company will provide excellent context for building scalable applications. By focusing on consistent data typing, you ensure your application remains predictable and easy to maintain.