gpt4 book ai didi

php - SQLSTATE[23000] : Integrity constraint violation: 1048 Column 'stickers' cannot be null Laravel

转载 作者:行者123 更新时间:2023-11-29 10:58:10 26 4
gpt4 key购买 nike

大家好,我的帖子表上有一行,我遇到了这个问题。

这是表格:

                    {{ 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');
}

这是我的 Controller “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)
{
//
}

贴纸行属于我的数据库中的帖子表,因此当我发布数据时会收到该错误消息。昨天它工作得很好,但是你移动了一些文件夹,并且意外地删除了部分代码,所以我再次编写了它,但有这个错误,以及这个社区帮助修复的另一个错误。

非常感谢

最佳答案

在您的模型中,将“贴纸”添加到可填充数组

protected $fillable = ['stickers']; //and any other mass asignable field. 

关于php - SQLSTATE[23000] : Integrity constraint violation: 1048 Column 'stickers' cannot be null Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42708725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com