'For each in Laravel API controller
I have an Axios request that sends an array of ids to generate a record for each of those ids. I try that through a foreach in the controller, but the postman throws me an error.
Too few arguments to function
Controller
function crearProductosAtributos(Request $request, $id_atributos)
{
try {
foreach ($request->$id_atributos as $key => $item) {
$productoatributo = new Productos_atributos_aplicado;
$productoatributo->id_atributo = $item->id;
$productoatributo->id_producto = $request->id_producto;
$productoatributo->created_by = auth()->id();
$productoatributo->save();
}
} catch (\Trowable $th) {
$this->capturar($th);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
