Skip to content

Commit dd172f3

Browse files
authored
Merge pull request #401 from 7thpark/patch-1
Update eloquent-mutators.md
2 parents edc4311 + 4a48bb4 commit dd172f3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

eloquent-mutators.md

+15-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,20 @@
5050

5151
$firstName = $user->first_name;
5252

53+
当然,你也可以通过已有的属性,使用访问器返回新的计算值:
54+
55+
```
56+
/**
57+
* 获取用户名全称
58+
*
59+
* @return string
60+
*/
61+
public function getFullNameAttribute()
62+
{
63+
return "{$this->first_name} {$this->last_name}";
64+
}
65+
```
66+
5367
<a name="defining-a-mutator"></a>
5468
### 定义一个修改器
5569

@@ -234,4 +248,4 @@
234248
>
235249
> 转载请注明:本文档由 Laravel China 社区 [laravel-china.org](https://laravel-china.org) 组织翻译,详见 [翻译召集帖](https://laravel-china.org/topics/5756/laravel-55-document-translation-call-come-and-join-the-translation)
236250
>
237-
> 文档永久地址: https://d.laravel-china.org
251+
> 文档永久地址: https://d.laravel-china.org

0 commit comments

Comments
 (0)