Error Array to string conversion


I am trying to send two arrays to my BD, an array of activities and another array of points !! so the form, and the error that throws me is an array to string conversion

I do not understand why, could you help me?

error 1/2 is:

here the html code:

<select multiple class="form-control" name="detalle.actividad_id" ng-model="puntuacion.detalle.actividad_id" ng-options=" as actividad.nombre for actividad in actividades | filter:{ circular_id: puntuacion.detalle.circular_id, tipo_a_id: 1}"></select> 
<input ng-repeat="actividad in actividades | filter:{ circular_id: puntuacion.detalle.circular_id, tipo_a_id: 1}" type="text" class="form-control"  name="detalle.puntos[]" ng-model="puntuacion.detalle.puntos[$index]" placeholder="@{{ actividad.puntuacion }}">

and the code in the laravel driver:

$datos = $request->detalle;
   foreach ($datos  as $key => $value) {
       $d = new Detalle();
       $d->puntuacion_id = $puntuacion->id;
       $actividad_id = $value;
       $d->actividad_id = $request->detalle['actividad_id'];
       $puntos = $request->puntos[$key];
       $d->puntos = $request->detalle['puntos'];


the data I want to be stored per row, so is the structure of the details table, there are several rows that I want to register at once and that is why I use a select multiple and several inputs! but I think the error is in the logic of the controller, can you help me ?? please!

asked by Ziul̺̿i̺̿n̺̿g̺̿ Maca̶yo 05.09.2017 в 04:11

2 answers


You must do the foreach in the two respective fields, not in all the request, however I consider that the way you are proposing it is not ideal.

This method assumes that you have the same number of values in activities and points:

$datos = $request->detalle;

$d = new Detalle();
$d->puntuacion_id = $puntuacion->id;

foreach ($datos['actividad_id'] as $index => $actividad) {
    $d->actividad_id = $actividad;
    $d->puntos = $datos['puntos'][$index];

In this case you would have two new records in the database, the first with activity 22 and points 75, and the second with activity 23 and points 200.

answered by 05.09.2017 / 05:34

Error 2/2

Parameters of type timestamp carry quotes, and you are trying to enter them without,

Error 1/2 is because you are passing arrays in the query, not a string like you should.

  • 6.

'22 ', array ('22', '33') , array ('75 ',' 200 ') ,' 2017-09-05 02 : 35: 20 ',' 2017-09-05 02:35:20 '

Second and third parameters are passing arrays with two values each, try with name of Variable [0] to pass' 22 'instead of array ('22', '33') in the second parameter

answered by 05.09.2017 в 05:06