1 回答

TA贡献1880条经验 获得超4个赞
Laravel 使用Str::class来处理字符串,对于其变元的名称,它使用方法camel。
以下字符串都将导致getStartedTradingCAttribute
Str::camel('get started trading c attribute')
Str::camel('get started_trading_c attribute')
Str::camel(' get started___trading__________c attribute')
Str::camel('get____started __ trading __c ___attribute')
您需要声明的方法是getStartedTradingCAttribute()
更多详情(方法简单)
public static function camel($value)
{
return lcfirst(static::studly($value));
}
public static function studly($value)
{
$key = $value;
$value = ucwords(str_replace(['-', '_'], ' ', $value));
return str_replace(' ', '', $value);
}
如您所见,所有_(下划线)都被替换为 (空格),然后什么都没有studly()
- 1 回答
- 0 关注
- 99 浏览
添加回答
举报