如何使用 echo 打印 Laravel 变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44427474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 16:06:10  来源:igfitidea点击:

How can print Laravel variable with echo

phplaravelecho

提问by Santiago García Cabral

<?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 $productin a template.

我需要$product在模板中打印变量。

回答by Mayank Pandeyz

You can echo it with php like:

您可以使用 php 回显它,例如:

<?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

这里只需要连接

回答by Shailesh Ladumor

you can print variable like that in blade

您可以在刀片中打印这样的变量

{{$product}}

{{$产品}}

see for more details in laravel official site

详情请见laravel官方网站