Need to pass array to route and controller

走远了吗. 提交于 2019-12-10 22:08:28

问题


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}].

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?


回答1:


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>



回答2:


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.




回答3:


Just use serialize($array);
Then pass this array to the route.



来源:https://stackoverflow.com/questions/47695202/need-to-pass-array-to-route-and-controller

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!