I'm using Laravel 5.4 and I'm handling my data with Vue 2. I'm Trying to call a controller method using axios, but I can't find a proper way to pass two arrays. I need to send them to my controller in order to make some database requests with them and get some data back.
I've manage to pass the arrays as strings as shown below, however, I would prefer not to transform the strings to arrays on my controller.
Could there be a way to do the same thing as I'm doing below but passing the arrays as arrays instead of strings or is this just not possible?
Axios call on Vue:
$rutas = ["01", "02"];
$tipos = ["01", "03", "04"];
var params = new URLSearchParams();
params.append("rutas", $rutas);
params.append("tipos", $tipos);
var request = {
params: params
};
axios.get('/test/', request);
This is my route
Route::get('/test/', 'TestsController@getClientesPorRuta');
This is my controller's method:
public function getClientesPorRuta(Request $request) {
$rutas = $request->input('rutas');
$tipos = $request->input('tipos');
// Code like this doesn't work
$index = 0;
$register = Ruta::where('CODIRUTA','=',$rutas[$index])->first();
}