【发布时间】:2017-08-21 10:43:33
【问题描述】:
我正在尝试提交表单并收到此错误
Connection.php 第 647 行中的 QueryException:SQLSTATE[23000]:违反完整性约束:1048 列“内容”不能为空(SQL:插入
content(title,content,image,@ 987654325@,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'));
}
}
【问题讨论】: