Search code examples
phplaravelstringmergelaravel-9

laravel component attributes value using "dot" character for merge string are not allowed?


first, I have followed all documentation about components. (tell me if I missed something)

Now, i have problems when adding laravel input component attribute value like this:

tried number 1:

<x-forms.input.text
    value="{{ $datas->product ? $datas->product->code . " - " . $datas->product->name : null }}"
/>

it's not working,

but when I change value like this:

tried number 2:

<x-forms.input.text
    value="{{ $datas->product ? $datas->product->code : null }}"
/>

it's working,

my question is:

  1. why merge string using "dot" notation not working?
  2. are they have best practices to merge string without a "dot" notation?

thanks

laravel version: 9.38.0

EDIT in view cache, I looking at this: (tried number 1) enter image description here when I remove the "dot" notation, they become like this: (tried number 2) enter image description here

I think the problem is in enter image description here at "red circle"


Solution

  • the problem is in my double quote:

    value="{{ $datas->product ? $datas->product->code . " - " . $datas->product->name : null }}"
    

    that must be a single quote:

    value="{{ $datas->product ? $datas->product->code . ' - ' . $datas->product->name : null }}"
    
                                                     here 👆