2016-12-26 68 views
0

嗨我試圖讓Laravel ORM工作,它不斷插入數據庫中的空記錄。已正確插入ID created_at和updated_at,但值不是。以下是文件:保存insterts空行Laravel 5.3

<?php 

namespace App; 

use Illuminate\Database\Eloquent\Model; 

class TesterTest extends Model 
{  
    protected $fillable = ['name','value']; 
    public $name; 
    public $value; 
} 

遷移文件:

<?php 

use Illuminate\Support\Facades\Schema; 
use Illuminate\Database\Schema\Blueprint; 
use Illuminate\Database\Migrations\Migration; 

class CreateTestTable extends Migration { 
    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('my_tests', function (Blueprint $table) { 
      $table->increments('id'); 
      $table->string('name'); 
      $table->integer('value'); 
      $table->timestamps(); 
     }); 
    } 

    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
     Schema::drop('my_tests'); 
    } } 

這是林怎麼叫它:

$flight = new TesterTest; 

$flight->name = "Tester1"; 

$flight->save(); 

有缺少的東西即時通訊,但不能弄明白。

+1

我想說在你的模型中加入'''public $ name;'''''public $ value;'''會導致問題。嘗試刪除這兩行。 – CUGreen

回答

2

我會說在你的模型中加入public $name;public $value;會導致問題。嘗試刪除這兩行。