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 關注
- 119 瀏覽
添加回答
舉報