2017-03-28 62 views
0

我試圖提交表單,我得到這個錯誤內容不能爲空laravel

QueryException在Connection.php行647:SQLSTATE [23000]:完整性約束違規:1048列「內容」不能(SQL:插入到contenttitle,content,image,updated_at,created_at)values(home,,[],2017-03-28 11:10:58,2017-03-28 11:10:58))

內容應該能夠爲空。

我遷移表

Schema::create('content', function(Blueprint $table) 
{ 
    $table->increments('id'); 
    $table->string('title'); 
    $table->text('content'); 
    $table->string('image'); 
    $table->timestamps(); 
}); 

我的存儲方法

public function store() 
{ 
    $input = Input::all(); 
    $validation = Validator::make($input, Content::$rules); 

    if($validation->fails()){ 
     return redirect()->route('content.create') 
      ->withInput() 
      ->withErrors($validation) 
      ->with('message', 'There were validation errors'); 
    } 

    if($validation->passes()){ 
     $content = new Content(); 

     $menuId = (array) array_get($input, 'menu_id'); 
     $content->fill($input)->save(); 
     $content->menu()->sync($menuId); 

     $content = Content::all(); 
     return view('content::admin.index', compact('content')); 
    } 
} 

回答

3
Schema::create('content', function(Blueprint $table) 
{ 
    $table->increments('id'); 
    $table->string('title')->nullable(); 
    $table->text('content'); 
    $table->string('image'); 
    $table->timestamps(); 
}); 

只需添加可爲空的列可以爲空

+1

'$表 - >文本( '內容' ) - >可空();'他希望內容爲空 –

+0

謝謝你們幫助 – Isis