php - In Laravel Eloquent inserts an empty record to table -


i have class word extends eloquent. have added 2 records manually, , fetching fine word::all() method. when i'm trying create new object , save it, eloquent inserts empty values table.

so, here model

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; } 

here database migration script

     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');      }); 

and here code i'm trying run

route::get('create', function() {     $n = new word;     $n->word         = "hello";     $n->language     = "en";     $n->senserank    = 1;     $n->partofspeech = "other";     $n->save(); }); 

and new record correct new id, other fields empty strings or zeros. how possible?

you need remove properties model because eloquent won't work should, class should this:

class word extends eloquent {     protected $table = 'words';     public $timestamps = false; } 

if need default values fields, add them example when creating table using default, example:

$table->tinyinteger('senserank')->default(1); 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -