如何在路由中发送数组并接收该数组

发布于 2025-01-15 02:48:51 字数 462 浏览 4 评论 0原文

我想发送一个数组作为参数进行路由并接收它。这是我的代码

$list = array_filter($list);
return redirect()->route('ucs.mail', serialize($list));

,我的路线是:

Route::get('customer/mail/{list}', 'CustomerActionController@send_mail')->name('ucs.mail');

当我尝试加载路线时,它会向我发送以下错误。 输入图片这里的描述

那么解决方案是什么呢?

I want to send an array to route as parameter and receive this. Here is my code

$list = array_filter($list);
return redirect()->route('ucs.mail', serialize($list));

And my route is:

Route::get('customer/mail/{list}', 'CustomerActionController@send_mail')->name('ucs.mail');

When I try to load the route it will send me following error.
enter image description here

So what is the solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

血之狂魔 2025-01-22 02:48:51

我在这里找到了我的解决方案:

方法1:

https://laracasts.com/discuss/channels/laravel/how-to-send-an-array-in-a-route-and-receive-this

方法2:可以解决另一种方式是:

使用 json 编码传递数组参数

return redirect()->route('ucs.mail', json_encode($list));

并进行 json 解码以在控制器中使用数组。

I found my solution following here:

Method 1:

https://laracasts.com/discuss/channels/laravel/how-to-send-an-array-in-a-route-and-receive-this

Method 2: It can be solved in another way like:

use json encode to pass array parameter

return redirect()->route('ucs.mail', json_encode($list));

and do json decode to use array in controller.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文