To be consistent over my coding style, I\'d like to use camelCase
to access attributes instead of snake_case
. Is this possible in Laravel without m
Since SO doesn't allow pasting code snippets in comments, I'm posting this as a new answer.
To make sure that eager loading does not break, I had to modify @Lazlo's answer. When accessing eagerly loaded relations by a different key, they are reloaded.
relations)) {
return parent::getAttribute($key);
} else {
return parent::getAttribute(snake_case($key));
}
}
public function setAttribute($key, $value)
{
return parent::setAttribute(snake_case($key), $value);
}
}