【问题标题】:How to insert value from combo box?如何从组合框中插入值?
【发布时间】:2019-08-10 07:28:03
【问题描述】:

我有一个包含模型数据的组合框。现在我想将这个组合框中的值保存到我的数据库中。当我保存它时返回以下错误消息:

SQLSTATE[23000]:违反完整性约束:1048 列“类型”不能为空。

来自该模型的数据返回组合框

class TypeProperties extends Model
{
     protected $table = 'type_properties';

     public static $types = [
         'textbox'  =>  'Textbox',
         'textarea' => 'Textarea',
     ];
}

组合框:

<select name="properties" class="form-control" name="type">
      @foreach($asset as $key =>$value)
              <option value="{{$key}}">
                    {{$value}}
               </option>
      @endforeach
</select>

功能保存:


function addPro(Request $req){
      $id = $req->type_id;
      $type = AssetType::find($id);
      $pro = new TypeProperties;
      $pro->name         = $req->name;
      $pro->code         = $req->code;
      $pro->type         = $req->type;
      $pro->assettype_id = $req->type_id;
      $pro->save();
      return redirect(url($type->id.'/add/property'))->with('message','Save successful');
}

【问题讨论】:

    标签: laravel combobox


    【解决方案1】:

    试试 print_r($req->type);

    在您的函数 addPro() 中检查天气值是否以表格形式发布。 你如何使用 ajax 或表单提交来提交表单?

    【讨论】:

    • 组合框返回的结果为空。我使用表单提交。
    • 您在选择标签中放置了两次名称属性,请检查并从中删除名称属性="properties"
    • 哦,我明白了,现在我可以保存它了。非常感谢。
    猜你喜欢
    • 2017-08-27
    • 1970-01-01
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-16
    相关资源
    最近更新 更多