Last active
October 3, 2017 18:45
-
-
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…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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