Home:ALL Converter>Comparing String against Object in Laravel Blade

Comparing String against Object in Laravel Blade

Ask Time:2022-12-10T10:47:17         Author:lerrrr8

Json Formatter

I ran into a weird issue with comparing an object against a string in a laravel's blade file.

I have a variable that could be a string("N/A") or an object depending on the result from the DB query, and I have the following condition checks:

@if ($a_string_name == 'N/A') 

If an object is returned, this condition will fail for most users and proceed to the else statement.

But for one specific case (I do not have enough information on how to reproduce this), this condition throws an error:

Method Illuminate\Support\Collection::__toString() must return a string value

I cannot figure out what went wrong, or if this is laravel/browser specific issue.

PHP v7.4.22, laravel v6.0

Author:lerrrr8,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74750011/comparing-string-against-object-in-laravel-blade
yy