简体   繁体   English

我如何将数据从刀片传递到刀片文件

[英]How do i pass data from blade to blade file

I try to pass two value from javascript to another blade file after click button to redirect to new window ...Here is my code单击按钮重定向到新窗口后,我尝试将两个值从 javascript 传递到另一个刀片文件...这是我的代码

ReportCreate.blade.php js ReportCreate.blade.php js


 $("#state").on("change", function() {
            var id = $(this).val();
            console.log(id)
            var cuid = document.getElementById("cu").value;  
            console.log(cuid)

        });

    </script>


Click button to open new window which is carry two value from javascript单击按钮打开新窗口,其中包含来自 javascript 的两个值

onclick="openNewWindow('{{ route('sla.slaCategoryTreeListScreen') }}')"

slaCategoryTreeListScreen.blade.php slaCategoryTreeListScreen.blade.php

<!DOCTYPE html>

<script>
// how do i retrieve two value from another blade file
</script>

</html>

First, You'll need to send those values when making the request.首先,您需要在发出请求时发送这些值。 You can do this with query params passing a second argument on the route() helper:您可以使用查询参数route()助手上传递第二个参数来执行此操作:

onclick="openNewWindow('{{ route('sla.slaCategoryTreeListScreen', ['id' => 123, 'cuid' => 456]) }}')"
                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Then, you get those values in your controller to finally return them to the second blade file:然后,您在控制器中获取这些值以最终将它们返回到第二个刀片文件:

# MyCoolController.php

public function toMySecondView(Request $request)
{
    $id = $request->get('id');
    $cuid = $request->get('cuid');

    return view('my_cool_second_view', ['id' => $id, 'cuid' => $cuid]);
}

Just then you'll be able to use them in your second view:届时您就可以在第二个视图中使用它们:

# my_cool_second_view.blade.php

<span> ID: { $id } </span>
<span> CUID: { $cuid } </span>

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

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