user8943958
user8943958

Reputation:

Need to pass array to route and controller

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?

Upvotes: 8

Views: 40693

Answers (3)

Sachin Vairagi
Sachin Vairagi

Reputation: 5344

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>

Upvotes: 6

Sagar Dave
Sagar Dave

Reputation: 97

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.

Upvotes: 5

Gothiquo
Gothiquo

Reputation: 868

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

Upvotes: 1

Related Questions