8

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?

5
  • could you show piece of code? Commented Dec 7, 2017 at 12:36
  • Route::get('/bookfromindex/actBook/{id}/{array}', 'BookController@actBook')->name('actBook'); Commented Dec 7, 2017 at 12:37
  • Controller: public function actBook(Request $request, $id, $array){ Commented Dec 7, 2017 at 12:38
  • view: <a href="{{ route('actBook', $room->id, $array) }}" class="btn btn-default">დაჯავშნა</a> Commented Dec 7, 2017 at 12:38
  • @GenoMumladze There is an edit function on questions, please edit your question next time to include the code instead of posting it as a comment. Commented Dec 7, 2017 at 12:51

3 Answers 3

6

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>
Sign up to request clarification or add additional context in comments.

Comments

5

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.

1 Comment

you are just echoing the result of that serialization right on the page there ... {{ }} is for echoing
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.