php - Laravel Blade Data display not applied correctly - Stack Overflow

admin2025-04-21  2

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\="" api\="" ?name="A+H&amp;color=7F9CF5&amp;background=EBF4FF&quot;}->mobile" class="underline">xxxxxxxx</a>

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>
Share Improve this question asked Jan 22 at 23:56 JesJes 758 bronze badges 1
  • I think you literally want to use {!! !!} instead of {{ }}, more info here – matiaslauriti Commented Jan 23 at 0:11
Add a comment  | 

1 Answer 1

Reset to default 1

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

转载请注明原文地址:http://anycun.com/QandA/1745223294a90424.html