Search code examples
laravelurl-routinglaravel-blade

Put the {{$p_id}} on {{URL::to}} on blade view on laravel 5.5


the below is work well

<button type="button" class="btn btn-default backurl"  data-href="{{URL::to('codo/a18/84')}}">
Go 
</button>

But I want to put the variable from the controller to the URL::to

{{$p_id}}=a18
{{$u_id}}=84

how can I write {{}} in {{}}

<button type="button" class="btn btn-default backurl"  data-href="{{URL::to('codo/{{$p_id}}/{{$u_id}}')}}">
Go 
</button>

I trid step by step

<button type="button" class="btn btn-default backurl"  data-href="{{URL::to('codo/{{$p_id}}/84')}}">
Go 
</button>

I got the error

"Parse error: syntax error, unexpected '}', expecting ',' or ')'"

on

 <button type="button" class="btn btn-default backurl"  data-href="<?php echo e(URL::to('codo/{{$p_id); ?>/84')}}">Go</button>

Solution

  • <button type="button" class="btn btn-default backurl"  data-href="{{URL::to("codo/$p_id/$u_id')}}">
    

    Actually you dont need to add braces again. {{}} this will compile to PHP and whatever you put in this will be treated as PHP.

    {{" hello world"}} // is equal to <?php echo "hello world" ?>
    

    Hope this helps.