1//The problem is caused by the fact that the Model's toArray() method ignores any accessors which do not directly relate to a column in the underlying table.
2
3//As Taylor Otwell mentioned here, "This is intentional and for performance reasons." However there is an easy way to achieve this:
4
5class EventSession extends Eloquent {
6
7 protected $table = 'sessions';
8 protected $appends = array('availability');
9
10 public function getAvailabilityAttribute()
11 {
12 return $this->calculateAvailability();
13 }
14}
15// ||| ||| ||| SOURCE HERE
16// vvv vvv vvv click here for ...
1$user = User::find(1);
2
3// add occupation to user instance
4$user->setAttribute('occupation', 'Web Developer');
1
2 public function getAvailabilityAttribute()
3 {
4 return $this->calculateAvailability();
5 }