For example, I have User model extending Eloquent. In the database table, the column name is user_id.
user_id
How do I output the result as \'userId\' after re
I do it in this way.
protected $remap_attrs = ['old_name' => 'new_name']; public function toArray(){ $array = parent::toArray(); foreach($this->remap_attrs as $key => $new_key) { if(array_key_exists($key, $array)) { $array[$new_key] = $array[$key]; unset($array[$key]); } } return $array; }