2016-12-26 67 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;会导致问题。尝试删除这两行。