Currently, I am utilizing Laravel 5.4 and Vue 2 to manage my data. I am facing an issue where I need to call a controller method using axios while passing two arrays. These arrays are crucial for making database requests in the controller and retrieving necessary data.
Although I have been able to pass the arrays as strings, I would prefer not to transform them back into arrays within the controller.
I am wondering if there is a way to achieve the same result but directly passing the arrays instead of converting them into strings first. Is this feasible at all?
Here's the Axios call made from 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);
Defined route:
Route::get('/test/', 'TestsController@getClientesPorRuta');
This snippet showcases the method within my controller:
public function getClientesPorRuta(Request $request) {
$rutas = $request->input('rutas');
$tipos = $request->input('tipos');
// The following code illustrates the issue faced when attempting to access array elements
$index = 0;
$register = Ruta::where('CODIRUTA','=',$rutas[$index])->first();
}