Search code examples
phplaravellaravel-blade

Laravel Blade Data display not applied correctly


So I got this statement in my Laravel Blade. And for some reason my curly braces are not being applied correctly inside of the Ternary statement.

<a {{ $item->User->mobile ? "href=tel:$item->User->mobile class=underline" : "" }}>{{ $item->User->mobile ?? "" }}</a>

As you can see from the below export from Chrome Console. The text itself, not the href attribute is being displayed correctly. But the same statement inside of the Ternary statement, only runs the first part "$item->User" And then at the end shows "->mobile". Which makes no sense. Is it just me. Or?

<a href="tel:{&quot;id&quot;:185,&quot;name&quot;:&quot;firsname" holl\u00e6nder&quot;,&quot;email&quot;:&quot;[email protected]&quot;,&quot;email_verified_at&quot;:null,&quot;two_factor_confirmed_at&quot;:null,&quot;profile_photo_path&quot;:null,&quot;created_at&quot;:&quot;2023-07-30t10:37:06.000000z&quot;,&quot;updated_at&quot;:&quot;2023-08-21t19:40:35.000000z&quot;,&quot;is_admin&quot;:0,&quot;mobile&quot;:&quot;20929775&quot;,&quot;profile_photo_url&quot;:&quot;https:\="" \="" ui-avatars.com\="" api\="" ?name="A+H&amp;color=7F9CF5&amp;background=EBF4FF&quot;}->mobile" class="underline">xxxxxxxx</a>

Solution

  • {{ $item->User->mobile ? "href=tel:{$item->User->mobile} class=underline" : "" }}