How can print Laravel variable with echo

33,242

You can echo it with php like:

<?php echo $product->product_id ?>

and in blade syntax like:

{{$product->product_id}}

and in your case it should be like:

'url' => [ '/cart/add/'. $product->product_id ]

only concatenation is required here

Share:
33,242
Santiago García Cabral
Author by

Santiago García Cabral

Updated on June 08, 2020

Comments

  • Santiago García Cabral
    Santiago García Cabral almost 4 years
    <?php echo Form::open(['method' => 'POST', 'url' => ['/cart/add/'. "{{$product->product_id }}"]] )?>
    <?php echo Form::button('Agregar al Carro', ['class' => 'btn-u btn-u-sea-shop btn-u-lg', 'type' => 'submit']) ?>
    <?php echo Form::close()  ?>
    

    I need to print the variable $product in a template.

  • Santiago García Cabral
    Santiago García Cabral almost 7 years
    I'm using a template with php
  • Shailesh Ladumor
    Shailesh Ladumor almost 7 years
    ok .see @Mayank Pandeyz's answer for template. thanks
  • Santiago García Cabral
    Santiago García Cabral almost 7 years
    <?php echo Form::open(['method' => 'POST', 'url' => ['/cart/add/'. $product->product_id ]] )?>
  • Santiago García Cabral
    Santiago García Cabral almost 7 years
    Undefined variable: product (View: /
  • Mayank Pandeyz
    Mayank Pandeyz almost 7 years
    That means product variable is not passed from controller to view and you are trying to access it.