【发布时间】:2014-11-11 11:07:50
【问题描述】:
我有扩展 Eloquent 的 Word 类。我手动添加了两条记录,它们使用Word::all() 方法可以很好地获取。但是当我尝试创建新对象并保存它时,Eloquent 会在表中插入空值。
所以,这是模型
class Word extends Eloquent {
protected $table = 'words';
public $timestamps = false;
public $word;
public $senseRank = 1;
public $partOfSpeech = "other";
public $language;
public $prefix;
public $postfix;
public $transcription;
public $isPublic = true;
}
这是数据库迁移脚本
Schema::create('words', function($table) {
$table->increments('id');
$table->string('word', 50);
$table->tinyInteger('senseRank');
$table->string('partOfSpeech', 10);
$table->string('language', 5);
$table->string('prefix', 20)->nullable();
$table->string('postfix', 20)->nullable();
$table->string('transcription', 70)->nullable();
$table->boolean('isPublic');
});
这是我要运行的代码
Route::get('create', function()
{
$n = new Word;
$n->word = "hello";
$n->language = "en";
$n->senseRank = 1;
$n->partOfSpeech = "other";
$n->save();
});
我得到的只是一个具有正确新 ID 的新记录,但所有其他字段都是空字符串或零。怎么可能?
【问题讨论】:
标签: php laravel laravel-4 eloquent