php - Laravel: Redirect with post routeGet the solution ↓↓↓
Been trying to find a way to call to pass a multidimensional array to a Post route with no success.
The array looks like this:
"order" => array:16 [ "id" => "1" "total" => "4825" "neighborhood" => "Barrio Bravo" ] "products" => array:2 [ 4 => array:4 [ "id" => "4" "name" => "Maestro Dobel 750ml" "price" => "530" "quantity" => "1" ] 1 => array:4 [ "id" => "1" "name" => "Don Julio 70 700ml" "price" => "650" "quantity" => "1" ] ] "grandTotal" => "1180" "balanceToPay" => "354" "cartTotal" => "826"
I don't have any problem asserting the route in the
unit test calling the route like so:
But when it comes to the controller I can't find the way to redirect to
order.success with its
This won't work since
redirect only works with
return redirect(route('order.success', $orderInfo));
It's not going to work with a simple redirection because you cannot choose the HTTP method. It's always GET when you make a redirection. It works in your test because you make a POST request manually.
I can see 2 solutions:
- You can send data using GET method (they are added as URL parameters). If they are not confidential it can be a solution.
- If you don't want to send those data in the URL, you have to save them somewhere and get them from the storage when you're on the order.success page. You can save them, for instance, in the session storage or in the local storage of your browser.
Also, your test isn't good if it tests a behavior that does not happen in your app (post request instead of redirection).
Share solution ↓
Link To Answer People are also looking for solutions of the problem: err_ossl_pem_no_start_line
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.