嗨大家即时通讯我的帖子表上有一行这个问题。SQLSTATE [23000]:完整性约束违规:1048'贴'栏不能为空Laravel
这是形式:
{{ Form::label('title', ' Título', array('class' => 'fa fa-pencil')) }}
{{ Form::text('title', null, array('class' => 'form-control', 'required' => '', 'maxlength' => '255', 'placeholder' => 'Ingresar Título')) }}
{{ Form::label('body', ' Contenido', array('class' => 'fa fa-pencil-square-o')) }}
{{ Form::textarea('body', null, ['class' => 'form-control', 'required' => '', 'placeholder' => 'Redactar Contenido']) }}
{{ Form::submit('Publicar', array('class' => 'btn btn-info')) }}
</div>
</div> <!-- col-md-8 end -->
<div class="col-md-4">
<div class="input-group">
<h3 class="text-center">Categoría e imágen</h3>
<hr>
<br> <hr>
{{ Form::label('stickers', ' Etiqueta', array('class' => 'fa fa-tags')) }}
{{ Form::text('stickers', '', array('class' => 'form-control', 'maxlength' => '20', 'placegolder' => 'Ingresar Etiqueta')) }}
<br> <hr>
{{ Form::label('postimg', ' Seleccionar Imagen', array('class' => 'fa fa-picture-o')) }}
{{ Form::file('postimg') }}
{!! Form::close() !!}
这是帖子移民文件:
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->string('stickers');
$table->text('body');
$table->string('postimg');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('posts');
}
这是我的控制器 “PostsController” 的一部分:
public function create()
{
return view('posts.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
// validate the data
$this->validate($request, array(
'title' => 'required|max:255',
'body' => 'required',
));
// store in database
$post = new Post;
$post->title = $request->title;
$post->body = $request->body;
$post->stickers = $request->stickers;
$post->postimg = $request->postimg;
$post->save();
Session::flash('success', 'La publicación se ha creado correctamente');
// redirect to another page
return redirect()->route('posts.show', $post->id);
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$post = Post::find($id);
return view('posts.show')->withPost($post);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
贴纸行属于我的数据库上的帖子表,所以当我发布数据时得到该错误信息。它昨天工作完美,但是y移动了一些文件夹,并且意外地删除了一部分代码,所以我再次写了它,但是有了这个错误,还有另外一个这个社区帮助解决的问题。
非常感谢
一点也没有看起来你需要在你的表单中添加贴纸,编辑迁移来创建这个属性 - > nullable()' – upful
你能展示你的模型是如何构建的吗?要查看您的模型中是否有数据通过可填充的属性 –
发送数据其实我的帖子模型是空的,我还没有处理它。它昨天工作正常,因为我说,但试图解决它我卡在那里 –