【发布时间】: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');
}
【问题讨论】: