皆さん、こんにちは、私の投稿テーブルの行にこの問題があります。SQLSTATE [23000]:整合性制約違反:1048列 'ステッカー'はnullにはできません。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はいくつかのフォルダを移動し、誤ってコードの一部を削除したので、私はこのバグとこのコミュニティが修正するのを助けた別のものを書きました。 NULL可能ならば、あなたのモデルでは
どうもありがとう
それはdoesnのあなたのフォームにステッカーが必要なように見える、このプロパティを作るために移行を編集する - > nullable() ' – upful
あなたのモデルがどのように構造化されているかを表示できますか?あなたのモデルにあなたが持っているかどうかを確認するには、プロパティfillableを介してデータを送信しています –
実際に私の投稿モデルは空です、私はまだそれに取り組んでいない。私は言ったが、それを修正しようとすると昨日はうまくいっていた。 –