驼峰命名法(camelCase)要求第一个单词以小写字母开头,之后所有的单词以大写字母开头并且不能包含任何空格或标点符号。下面是一些驼峰命名法示例:
- “iPhone”
- “eBay”
- “personWeight”
- “statueHeight”
- “birthYear”
- “studentFirstName”
- “studentLastName”
Laravel 提供了一个字符串辅助函数 Str::camel 用来将字符串转换为驼峰方式。示例如下:
use IlluminateSupportStr;
// snake_case方式的字符串转换
echo Str::camel('student_first_name');
// kebab-case方式的字符串转换
echo Str::camel('student-first-name');
// StudlyCase(PascalCase)方式的字符串转换
echo Str::camel('StudentFirstName');
以上三种方式的字符串均会转换成:studentFirstName