Global Mutator for Laravel
问题 I have many different locations ways of inserting and updating my database and I would like to be able to trim() the users input before inserting into the database. I know in the model I can do something like below, but I do not want to do this for every field. Is there a way to set a generic setter that works on all fields? Example: public function setSomFieldAttribute($value) { return $this->attributes['some_field'] = trim($value); } 回答1: You probably will be able to override those methods: