简体   繁体   English

从多个输入Laravel 5插入数据库

[英]Insert to database from multiple inputs Laravel 5

The response from the request is forbidden. 禁止来自请求的响应。 I really don't know why. 我真的不知道为什么。

I am trying to just insert into the database data from multiple inputs. 我试图从多个输入插入数据库数据。 The single inputs are stored correctly. 单个输入正确存储。 The request has not any rules, so it is impossible that the error comes from there. 请求没有任何规则,因此错误不可能来自那里。

Let me show you my code: 让我告诉你我的代码:

 public function store(CreateRequest $request)
 {  
      $l = new l();
      $l->user_id = $request->input('registered');
      $l->description = $request->input('descri');
      $l->save();
      $lastInsertedId= $l->id;              
      $input = $request->all();
      $condition = $input['nym'];
      foreach ($condition as $key => $condition) {
         $le = new le();    
         $le->lid = $lastInsertedId;
         $le->deman = $input['nym'][$key];
         $le->dni = $input['dni'][$key];
         $le->address = $input['address'][$key];
         $le->contact_number = $input['contactnum'][$key];
         $le->def = $input['abo'][$key];
         $le->defe = $input['pro'][$key];
         $le->created_at = date('Y-m-d h:i:s');
         $le->save();
     }
     return redirect('blog')->with('ok', trans('back/blog.stored'));
}

The info for the multiple inputs is coming from here: 多个输入的信息来自这里:

<tbody class="input_fields_wrap">      
    <tr>
       <td><input type="text" name="nym[]" value="que" readonly="" style="outline:none;border:none;border-width:0px;"></td>
       <td><input type="text" name="dni[]" value="funci" readonly="" style="outline:none;border:none;border-width:0px;"></td>
       <td><input type="text" name="address[]" value="one" readonly="" style="outline:none;border:none;border-width:0px;"></td>
       <td><input type="text" name="contactnum[]" value="13" readonly="" style="outline:none;border:none;border-width:0px;"></td>
       <td><input type="text" name="abo[]" value="nem" readonly="" style="outline:none;border:none;border-width:0px;"></td>
       <td><input type="text" name="pro[]" value="por" readonly=""</td>
       <td><a class="remove_field">Eliminar</a></td>
    </tr>
</tbody>

I have solved the problem. 我已经解决了这个问题。

I modified the model adding fillable propeties: 我修改了添加可填充属性的模型:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Flight extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name'];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM