laravel 需要将数组传递给路由和控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47695202/
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
Need to pass array to route and controller
提问by
I need to pass array to route and controller from view.
我需要从视图中将数组传递给路由和控制器。
I get the error:
我收到错误:
Missing required parameters for
[Route: actBook] [URI: bookfromindex/actBook/{id}/{array}]
.
缺少所需的参数
[Route: actBook] [URI: bookfromindex/actBook/{id}/{array}]
。
I have my route defined as:
我的路线定义为:
Route::get('/bookfromindex/actBook/{id}/{array}', 'BookController@actBook')->name('actBook');
My controller function is defined as:
我的控制器功能定义为:
public function actBook(Request $request, $id, $array){
And I call this route in my view using:
我在我看来使用以下方法调用这条路线:
<a href="{{ route('actBook', $room->id, $array) }}" class="btn btn-default">????????</a>
How do I prevent this error?
如何防止此错误?
采纳答案by Zeeweesoft
Just change -
只是改变 -
<a href="{{ route('actBook', $room->id, $array) }}" class="btn btn-default">????????</a>
to -
到 -
<a href="{{ route('actBook', $room->id, serialize($array)) }}" class="btn btn-default">????????</a>
回答by Sagar Dave
First, you need to serialize your array then you can pass into the parameter
首先,您需要序列化您的数组,然后您可以传入参数
Example :
例子 :
{{ $serializeArray = serialize($array) }}
<a href="{{ route('actBook', $room->id, $serializeArray) }}" class="btn btn-default">
Controller :
控制器 :
public function actBook(Request $request, $id, $array){
Route :
路线 :
Route::get('/bookfromindex/actBook/{id}/{array}', 'BookController@actBook')->name('actBook');
Hope this will help you.
希望这会帮助你。
回答by Moslem Ch
Just use serialize($array);
Then pass this array to the route.
只需使用serialize($array);
然后将此数组传递给路由。