laravel类型错误:传递给的参数1必须是类型数组,给定整数

时间:2018-02-21 00:57:28

标签: jquery html laravel

我想保存一个请求,同时使用相同的ID保存随附文章的详细信息。

  public function store(Request $request){
       $this->solicitud->save();
     foreach ($request->descripcion as $data ) {
      $detalle              = new Detalle();
      $detalle->cantidad = Input::get('cantidad');
      $detalle->descripcion = Input::get('descripcion');
      $this->solicitud->detalles()->save($detalle);

      }}

模型Detalle

  protected $fillable=[ 'cantidad','descripcion','solicitud_id']; 
public function something()
   {
       return $this->belongsTo(Solicitud::class, 'solicitud_id');
   }

模型Solicitud

 protected $fillable=['titulo','fundamento','estado','slug','departamento_id','user_id'];
    public function detalles()
    {
        return $this->hasMany(Detalle::class, 'solicitud_id');
    }
}

<html>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

<table class="table table-bordered" id="dynamic_field">
                         <thead>
                           <tr>
                             <th style="width:50px" scope="col">Cantidad</th>
                             <th scope="col">Descripcion</th>
                             <th></th>

                           </tr>
                         </thead>
                         <tbody>
                           <tr>
                             <td><input type="text" name="cantidad[]" placeholder="Cantidad" class="form-control name_list" /></td>
                             <td><input type="text" name="descripcion[]" placeholder="Descripcion" class="form-control name_list" /></td>
                             <td><button type="button" name="add" id="add" class="btn btn-success">Agregar + </button></td>

                           </tr>


                         </tbody>
                        </table>
                        <script
              src="http://code.jquery.com/jquery-3.3.1.js"
              integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="
              crossorigin="anonymous"></script>

                          <script>
$(document).ready(function(){
   var i=1;
   $('#add').click(function(){
        i++;
        $('#dynamic_field').append('<tr id="row'+i+'"><td><input type="text"name="cantidad[]" placeholder="Cantidad" class="form-control name_list" /><td><input type="text"name="descripcion[]" placeholder="Descripcion" class="form-control name_list" /></td><td><button type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove">Quitar</button></td></tr>');
   });
   $(document).on('click', '.btn_remove', function(){
        var button_id = $(this).attr("id");
        $('#row'+button_id+'').remove();
   });

});
</script>
                        </html>

我收到了这个错误

  

类型错误:传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须是类型数组,   给定的整数,调用   C:\ XAMPP \ htdocs中\ proyect \供应商\ laravel \框架的\ src \照亮\数据库\查询\语法\ Grammar.php   在第681行

我希望我能很好地解释自己。问候 对不起我的英语嘿嘿

Detalle {#234 ▼
  #fillable: array:3 [▼
    0 => "cantidad"
    1 => "descripcion"
    2 => "solicitud_id"
  ]
  #connection: null
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #attributes: array:2 [▼
    "cantidad" => array:2 [▼
      0 => "3"
      1 => "3"
    ]
    "descripcion" => array:2 [▼
      0 => "Pants"
      1 => "Tshirt"
    ]
  ]
  #original: []
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▶]
}

0 个答案:

没有答案