问题
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