Search code examples
laravellaravel-blade

Laravel and Blade - how to write a variable inside quotes?


I am trying to produce something like

id="checkout-button-{someid}"

For instance

id="checkout-button-jjn5jghj5"

I thought this would be done through unescaped strings doing this

id={!! "checkout-button-$item->id" !!}

But this is not producing the variable in the string.

What is proper way to do this in blade views?


Solution

  • Blade is going to

    1. Look for the opening {{
    2. Capture everything before the closing }}, and then
    3. Evaluate the expression and use that value to replace the entire {{ ... }} string

    In your case, the only thing you need Blade for is getting the id. So your statement should look like this:

    id="checkout-button-{{ $item->id }}"