简体   繁体   English

Laravel - 将部分会话内容添加到数组中

[英]Laravel - add part of session content into array

I am looking to move a part of a session into a variable.我希望将会话的一部分移动到变量中。 The blade echo works fine outside the php tags.刀片回声在 php 标签之外工作正常。 Inside the pgh tags I get an error about '{'.在 pgh 标签内,我收到关于“{”的错误。

Question: How can I move the mentioned session content into a PHP variable?问题:如何将提到的会话内容移动到 PHP 变量中? If possible I would like to stay with using blade echo.如果可能的话,我想继续使用刀片回声。

My code:我的代码:

{{ session('payment.request_payment_id') }} // This works.

@php
  $test = {{ session('payment.request_payment_id') }} // This shows error
@endphp

Error:错误:

syntax error, unexpected '{' (View: Xxx.blade.php)

Its all PHP between these directives:它在这些指令之间的所有 PHP:

@php
    $test = session('payment.request_payment_id');
@endphp

Update:更新:

If you really think you need to also be echoing this as your question is asking:如果你真的认为你也需要在你的问题中回应这一点:

{{ $test = session('payment.request_payment_id') }}

Everything inside {{ ... }} is PHP. {{ ... }}里面的一切都是 PHP。

here {{ }} it means in blade <?php echo ?>这里{{ }}表示刀片<?php echo ?>

and

@php
@endphp

it translate to <?php ?>它转换为<?php ?>


so when ur trying to所以当你试图

@php
  $test = {{ session('payment.request_payment_id') }} // This shows error
@endphp

it convert in to它转换为

<?php
$test = <?php echo session('payment.request_payment_id') ?>
?>

which is wrong and above answer given by lagbox is correct use that这是错误的,上面由lagbox给出的lagbox是正确的使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM