I'm trying to create a route in Lumen that takes in two arrays as arguments. So, as my route in web.php
I have the following:
$router->get('matrix/mul/{m1}/{m2}', ['uses' => 'MatrixController@multiplyMatrix']);
Where m1 and m2 are supposed to be array 1 and array 2. Then in the controller I have following:
public function multiplyMatrix(array $m1, array $m2) {
var_dump($m1);
var_dump($m2);die;
}
Very simple, I just want to make sure the values are getting there as arrays. But when I try to access the route through the browser with both http://localhost:8000/matrix/mul/m1[0,1]/m2[2,3]
and http://localhost:8000/matrix/mul/m1[]=0/m2[]=2
I get the same error: Argument 1 passed to App\Http\Controllers\MatrixController::multiplyMatrix() must be of the type array, string given
.
I know that my problem is probably in the way I'm building the url. Any idea on how can I make this work?
Arrays which you pass in route are json-encoded. Just decode them in controller and replace array
casting with string
.