Skip to content

Instantly share code, notes, and snippets.

@ruslanashaari
Last active October 3, 2017 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruslanashaari/f50dc7705dfc07685bcaf3697d13bd29 to your computer and use it in GitHub Desktop.
Save ruslanashaari/f50dc7705dfc07685bcaf3697d13bd29 to your computer and use it in GitHub Desktop.
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: https://laravel.com/docs/5.1/eloquent-serialization#appending-values-to-json s/o ref: https://st…
//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';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment