【发布时间】:2016-12-14 21:05:59
【问题描述】:
我正在使用 Bootforms 来编辑博客上的帖子
<?php $formOptions = [
'url' => 'user',
'sm' => [2, 5],
'lg' => [2, 5],
'method'=> 'put'
]; ?>
{!! BootForm::openHorizontal($formOptions)->action(route('news.update', $post)) !!}
<input type="hidden" name="_method" value="PUT">
{!! BootForm::text('Titre', $post->title) !!}
{!! BootForm::text('Slug', $post->slug) !!}
{!! BootForm::textarea('Contenu', $post->content) !!}
{!! BootForm::submit('Editer') !!}
{!! BootForm::close() !!}
这是我更新帖子后的 PostController 函数:
public function update($id, Request $request)
{
$post = Post::findorFail($id);
$title = $request->input('title');
$post->title = $title;
$post->content = $request->input('Contenu');
$request->has('save');
$post->save();
return redirect(route('news.index'));
}
但是一旦我编辑了我的帖子,我就会遇到这个错误,就像我发送空字符串一样:SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null (SQL: update posts set title = , content = , updated_at = 2016-12-14 20:48:25 其中id = 3)
如果您发现问题出在哪里,我可以寻求帮助...
【问题讨论】:
-
错误再清楚不过了,它告诉您您正在尝试在数据库中插入一个空的(NULL)“标题”字段,并且该字段被定义为非空。
-
我知道,我说我知道它正在发送空字符串。问题是我不知道如何解决它。但是感谢您的帮助..
-
哎呀,没意识到,抱歉讽刺了。