Laravel Model conditional formatting
问题 I have a database and model called Vote_actions that looks like this: id group_id user_id action_type anonymous (boolean) User can ask to be anonymous (that would make the boolean value to be true).If that is the case, I want to change the group_id and user_id from the returned model to -1. Is there a way in laravel that I can do it ? 回答1: You are leaning towards an edge case, with special conditions. Make use of accessors: class VoteActions extends \Eloquent { public $casts = [ 'anonymous' =