2017-03-10 16 views
0

皆さん、こんにちは、私の投稿テーブルの行にこの問題があります。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可能ならば、あなたのモデルでは

どうもありがとう

+0

それはdoesnのあなたのフォームにステッカーが必要なように見える、このプロパティを作るために移行を編集する - > nullable() ' – upful

+0

あなたのモデルがどのように構造化されているかを表示できますか?あなたのモデルにあなたが持っているかどうかを確認するには、プロパティfillableを介してデータを送信しています –

+0

実際に私の投稿モデルは空です、私はまだそれに取り組んでいない。私は言ったが、それを修正しようとすると昨日はうまくいっていた。 –

答えて

1

は、ステッカーの欄に入力可能な配列

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

私はこのエラーを受け取ります: VerifyCsrfToken.phpの68行目のTokenMismatchException 6838: –

+0

フォームにcsrfトークンがないか、すでにトークンが期限切れになっています。 'Form :: open()'を使いますか? – EddyTheDove

+0

はいフォームを開いて使用しています –

0

に を 'ステッカー' を追加します(NULL可能を追加)連鎖方式

$table->string('stickers')->nullable(); 
+0

ありがとうございました、私はそれをしました:D問題はこれでした: 'maxlength' => '20' 私はそれを取り除き、問題を解決しました。 実際に私が画像ファイルフィールドを持たない新しい投稿をしたとき、同じエラーが出るので、私のステッカーテーブルは255文字の文字列で、私はparsley.cssとparsley.jsで25に制限しました。私のフォームから外してください。君たちありがとう –

関連する問題