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
Author by
Santiago García Cabral
Updated on June 08, 2020Comments
-
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 almost 7 yearsI'm using a template with php
-
Shailesh Ladumor almost 7 yearsok .see @Mayank Pandeyz's answer for template. thanks
-
Santiago García Cabral almost 7 years<?php echo Form::open(['method' => 'POST', 'url' => ['/cart/add/'. $product->product_id ]] )?>
-
Santiago García Cabral almost 7 yearsUndefined variable: product (View: /
-
Mayank Pandeyz almost 7 yearsThat means
product
variable is not passed from controller to view and you are trying to access it.