大家好,我的帖子表上有一行,我对此有疑问。
形式如下:
{{ 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)
{
//
}
贴纸行属于我的数据库上的posts表,因此当我发布数据时会收到该错误消息。昨天它运行良好,但是您移动了一些文件夹,并且不小心删除了部分代码,因此我再次写了它,但是有那个错误,还有一个由社区帮助修复的错误。
非常感谢
最佳答案
在模型中,将“ stickers”添加到可填充数组
关于php - SQLSTATE [23000]:违反完整性约束:1048列“stickers”不能为空Laravel,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42708725/