2014-11-21 15 views
0

我試圖創建一個聯繫人的條目:與雄辯創建的條目 - 意外behavoiur

Contact::create([ 
      'firstname' => $faker->firstName, 
      'lastname' => $faker->lastName, 
      'email' => $faker->email, 
      'location_id' => 6, 
      'department_id' => 3 
     ]); 

在模型Contact.php:

protected $fillable = [ 
    'firstname', 
    'lastname', 
    'location_id', 
    'department_id', 
    'email' 
]; 

遷移代碼:

Schema::create('contacts', function(Blueprint $table) 
    { 
     $table->increments('id'); 
     $table->string('firstname'); 
     $table->string('lastname'); 
     $table->integer('location_id')->nullable(); 
     $table->integer('department_id')->nullable(); 
     $table->string('email')->unique(); 
     $table->timestamps(); 
    }); 

如果我只是嘗試使用名字,姓氏和電子郵件創建它,它工作正常。但由於某種原因,它不適用於填充的location_id和department_id字段。該條目沒有出現在數據庫中,但沒有錯誤消息。我究竟做錯了什麼?

+0

「但由於某些原因,它不工作」是不是一個錯誤消息。 – 2014-11-21 15:46:48

+0

我沒有收到錯誤消息 - 它通過很好,但不會在數據庫中創建條目。我已經更新了提交。 – babbaggeii 2014-11-21 15:56:25

+0

嘗試在'create'調用之後運行'DB :: getQueryLog()'。看看它做了什麼。 – 2014-11-21 15:58:25

回答

-1

讓我們試試這個

// app/models/Location.php 
class Location extends Eloquent { } 

// app/models/Department.php 
class Department extends Eloquent { } 

,並遷移到更新

Schema::create('contacts', function(Blueprint $table) 
{ 
    $table->increments('id'); 
    $table->string('firstname'); 
    $table->string('lastname'); 
    $table->integer('location_id')->unsigned(); 
    $table->integer('department_id')->unsigned(); 
    $table->string('email')->unique(); 
    $table->timestamps(); 
});