9/24/2017 - 8:43 PM

append a value column into json/array

any custom property that we want to append to any json/array representative from model.

  1. add a public function getter using a camel case of the column to define the column value
  2. set a protected array of the column

p/s: laravel 5.1 above doc ref: s/o ref:

//in model Reply.php

protected $appends = ['favoritesCount'];

//so when data are being called from this model, element favoritesCount are included in the json/array

//another example from stackoverflow

class User extends Eloquent {
 protected $appends = array('status');

    public function getStatusAttribute() {
      return 'someStatus';