Attempt to read property "name" on bool laravel 8, variable not transfering to view

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Understanding and Resolving Laravel 8 Boolean Error When Transferring Variables to View Introduction Laravel is an exceptional framework for web development with many useful features. However, sometimes errors can happen when using particular functionalities. One such issue is encountered with the error "Attempt to read property "name" on bool" or "Variable not transfered to view". In this blog post, we will explain why and how to fix this issue in your Laravel 8 application with PHP 8. Cause of the Error The primary reason for this error is that you might be trying to access a non-existent property within a Boolean value or an undefined variable. In most cases, this indicates a mistake in the code that sends data between controllers and views. It's essential to understand how Laravel handles variables throughout your application. Solution 1: Check the Controller Function Logic Firstly, look at the code block that performs the operations on the controller function. In our scenario, we have a route called 'employees/{id}/payslip'. The controller's print() function first finds the employee using their ID and then retrieves data from related tables such as teams. Then, it returns the view with the necessary data: ```php public function print($id) { $employees = Employees::findOrFail($id); $teams = Team::all(); return view('employees.payslip', compact('employees', 'teams')); } ``` Ensure that the data you are passing to your controller is valid and not null or just a Boolean value, which can cause the error. For instance, if you're sending an employee_id and it doesn't exist in the database, this issue might arise. Correct this part of your code accordingly. Solution 2: Check the View File Logic Next, you need to check the Blade (or view) file used for the 'employees/payslip' route. In the code block shown above, the view is called 'employees/payslip', and it loops through employees and displays their details using their objects. Since we provided a Boolean variable or non-existent property in the controller function, the error occurs when accessing these variables within the view: ```html {{$employee->name}} ``` To resolve this issue, ensure that the variables you're using within your Blade (or view) file are defined and valid. Double-check if you've passed the correct information from your controller to the view, or check for typos in these variable names. Solution 3: Use Ternary Operator (Optional) If you find that some of your data is still undefined in your controller function, you can use Laravel's ternary operator to provide a default value if the necessary information isn't available: ```php public function print($id) { $employees = Employees::findOrFail($id); $teams = Team::all(); return view('employees.payslip', compact('employees', 'teams')); } ``` Conclusion By ensuring that all your data is valid and the variables you're using with your Laravel 8 application are defined, you can avoid the "Attempt to read property "name" on bool" or "Variable not transfered to view" error. Remember to use proper naming conventions for your variables and double-check if they are correctly passed between controllers and views. Always include necessary checks or default values in your code to prevent such issues from occurring. For further assistance, refer to the Laravel documentation or contact a professional web development team like https://laravelcompany.com to help build and maintain your application.