php - Make Trait protected attributes accessible to Eloquent in Laravel 4.2 -


i'm new using traits , having trouble saving protected attributes of trait within eloquent model:

here route model:

namespace app\models; use eloquent;  class route extends eloquent {      use cardtrait {         cardtrait::__construct __cardconstruct;     }      public $timestamps = false;     protected $table = 'routes';     protected $primarykey = 'id';     protected $visible = [         'name',         'description'     ];      public function __construct(array $attributes = array())     {         $this->__cardconstruct($attributes);     }     //relationships follow } 

and here cardtrait trait:

namespace app\models;  trait cardtrait {      protected $timesasked;     protected $factor;     protected $nexttime;      public function __construct($attributes = array(), $timesasked = 0, $factor = 2.5, $nexttime = null)     {         parent::__construct($attributes);          if (is_null($nexttime)) $nexttime = \carbon::now()->todatetimestring();         $this->factor = $factor;         $this->nexttime = $nexttime;         $this->timesasked = $timesasked;          public function answer($difficulty)         {             if($difficulty < 3)                 $this->timesasked = 1;         }         //other methods follow } 

in controller can use:

$route = new route(); $route->name = "new name"; $route->description = "new description"; $route->answer(5); $route->save(); 

name , description save fine, , although have columns timesasked, factor , nexttime when dd($route) can see

protected 'timesasked' => int 1 protected 'factor' => float 2.6 protected 'nexttime' => string '2015-04-15 21:36:53' (length=19) 

so know methods of trait working fine.

my question how can save these values eloquent these can stored , retrieved database?

thanks in advance.

eloquent store values in internal attributes array. written database. not write values attributes array if exist data member on model. __set , __get magic methods , how used in illuminate/database/eloquent/model

so long story short, remove protected data members model.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -