1 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊
模型
public function setScreenNameAttribute($value)
{
$this->attributes['screen_name'] = strtolower(strtok($value, ' ')); // First name from the full name as screen name
}
控制器
$user->screen_name = 'John Smith'; // your request value goes here - $request->full_name;
您不需要在表單中為此設(shè)置字段。
希望這可以幫助。
如果不起作用,請告訴我。
更新/另一個(gè)解決方案。
protected $attributes = array(
'screen_name' => 'Your name' // Any values
);
public function __construct(array $attributes = array())
{
$this->setRawAttributes(array(
'screen_name' => strtolower(strtok($attributes->first_name, ' '));
), true);
parent::__construct($attributes);
}
- 1 回答
- 0 關(guān)注
- 124 瀏覽
添加回答
舉報(bào)