php - Laravel with Eloquent doesn't save model properties on database -


i'm buiding web app using php laravel framework. when save model on database makes insert doesn't save model properties. can't see how fix because laravel log doesn't show mistake. idea?

there's model:

/**  * database table used model.  *  * @var string  */ protected $table = 'test'; //  protected $fillable = array('name', 'surname', 'mobile', 'phone', 'mail', 'adress');  // model properties private $name; private $surname; private $mobile; private $phone; private $mail; private $adress;  // model constructor function __construct($name, $surname, $mobile, $phone, $mail, $adress) {     $this->name = $name;     $this->surname = $surname;     $this->mobile = $mobile;     $this->phone = $phone;     $this->mail = $mail;     $this->adress = $adress; } 

and there's php code create user object , save database

<?php  // create object using model's constructor $user = new user('john', 'doe', 685412578, 9354784125, 'j@doe.com', 'portland');  // show properties echo '<p>'.$user->getname().'</p>'; echo '<p>'.$user->getsurname().'</p>';  // saving model on database $user->save();  ?> 

when execute php code show on screen model properties , makes insert doesn't save properties. great if can me :)


there's solution (if has same problem or similar)

model:

    protected $table = 'test';      // fields on databse save model properties     protected $fillable = array('name', 'surname', 'mobile', 'phone', 'mail', 'adress');      // model properties     private $name;     private $surname;     private $mobile;     private $phone;     private $mail;     private $adress; 

and php code:

 <?php          // create object                     $user = user::create(array(                         'name'=>'john',                          'surname'=>'doe',                          'mobile'=>685412578,                          'phone'=>9354784125,                          'mail'=>'j@doe.com',                          'adress'=>'portland'                         ));          // show properties         echo '<p>'.$user->name.'</p>';         echo '<p>'.$user->surname.'</p>';          // saving model on database         $user->save();      ?> 

as described @ http://laravel.com/docs/eloquent#mass-assignment, need $fillable property set properties want mass-assignable. should therefore uncomment line starting protected $fillable = ....


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -