2014-09-27 111 views
0

我正面臨以下錯誤,當我嘗試創建數據到數據庫中時: [2014-09-27 09:02:40] production.ERROR:exception'Illuminate \ Database \ Eloquent \在電子商務MassAssignmentException」有消息 '名':\網絡\ XAMPP \ htdocs中\ laravel \引導\ compiled.php:6397laravel 4.2未創建到數據庫中

在new.blade.php文件:

@extends('layouts.default') 

@section('content') 

    <h1>New Author page</h1>  

    {{ Form::open(array('url' => 'authors/create', 'method' => 'POST')) }} 


    <p> 
     {{ Form::label('name', 'Name:') }} 
     {{ Form::text('name') }} 
    </p> 

    <p> 
     {{ Form::label('bio', 'Biography:') }} 
     {{ Form::textarea('bio') }} 
    </p> 

    <p> 
     {{ Form::submit('Add Author') }} 
    </p> 

    {{ Form::close() }} 

@endsection 

和routes.php文件我的路線設置爲:

Route::get('authors', array('uses'=>'[email protected]', 'as'=>'authors')); 
Route::post('authors/create', array('uses'=>'[email protected]', 'as'=>'create_author')); 

在我Authorscontroller.php文件以下等爲代碼:

public function create() 
    { 
     Author::create(array(
      'name' => Input::get('name'), 
      'bio' => Input::get('bio') 
      )); 
     return Redirect::route('authors'); 
    } 

這裏是版本4.2 laravel問題?

+0

可能重複[Laravel 4照亮\數據庫\雄辯\ MassAssignmentException錯誤](http://stackoverflow.com使用質量分配/ questions/22747061/laravel-4-illuminate-database-eloquent-massassignmentexception-error) – Marwelln 2014-09-27 10:22:53

回答

0

在你的模型中你必須給私人$守衛=數組('ID');這裏的id是表的主鍵,這意味着當你使用create或者update方法時,使用批量賦值時,保護數組中的給定字段將不會被更新!您必須在模型中定義此屬性格式使用create()或update()方法

private $guarded = array('id'); //id is primary key where it can be any field which will not be updated in mass assignment 
+1

Sam謝謝你的回覆,現在它的工作 – 2014-09-28 05:54:19

+0

隨時..你是最受歡迎的.. :) – 2014-09-29 09:13:24