1
I need to pass an array to a controller. I did it as below but it returns the error:
Missing required parameters for [Route: site.add.cart] [URI: adiciona-carrinho/{product}/{option}]. (View: /var/www/html/ecommerce/resources/views/site/pages/product/product.blade.php)
View:
<div class="col-12 offset-lg-6">
@php
$array = [1, 2];
@endphp
<a id="add-cart" href="{{ route('site.add.cart', ['product' => $product, 'option' => serialize($array)]) }}" class="btn btn-primary mt-5">Adicionar ao Carrinho</a>
</div>
Route:
Route::get('/adiciona-carrinho/{product}/{option}', 'CartController@addCart')->name('site.add.cart');
Controller
public function addCart(Product $product, $option)
{
dd($option);
}
You need to pass the option parameter, without being serialized, and work that information on
controller
? got it– novic
But I need to pass an array on the route. I saw in another question the use of serialize this way. I ended up getting through with json_encode but I wanted to know why serialize does not work.
– Marcelo
Because of the output format of
serialize
, now as you’ve managed to pass withjs_encode
that would be ajson
, put this as an answer! if your question is not valid, it will not help anyone– novic