我试图提交表单,但我收到了此错误
Connection.php第647行中的QueryException:SQLSTATE [23000]:完整性约束违规:1048列'内容'不能为空(SQL:插入
content
(title
,content
,image
,updated_at
,created_at
)值(home ,, [ ],2017-03-28 11:10:58,2017-03-28 11:10:58))
内容应该可以为空。
我的迁移表
Schema::create('content', function(Blueprint $table)
{
$table->increments('id');
$table->string('title');
$table->text('content');
$table->string('image');
$table->timestamps();
});
我的商店方法
public function store()
{
$input = Input::all();
$validation = Validator::make($input, Content::$rules);
if($validation->fails()){
return redirect()->route('content.create')
->withInput()
->withErrors($validation)
->with('message', 'There were validation errors');
}
if($validation->passes()){
$content = new Content();
$menuId = (array) array_get($input, 'menu_id');
$content->fill($input)->save();
$content->menu()->sync($menuId);
$content = Content::all();
return view('content::admin.index', compact('content'));
}
}
答案 0 :(得分:3)
Schema::create('content', function(Blueprint $table)
{
$table->increments('id');
$table->string('title')->nullable();
$table->text('content');
$table->string('image');
$table->timestamps();
});
只需在可以为null的列上添加nullable