您好我试图让Laravel ORM正常工作并且它一直在数据库中插入空记录。已正确插入ID created_at和updated_at,但值不是。以下是文件:
<?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();
有一些东西我想念但是无法弄明白。
答案 0 :(得分:2)
我想说在模型中添加public $name;
和public $value;
会导致问题。尝试删除这两行。