Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate eloquent-serialization.md (v5.5) #381

Merged

Conversation

Nationalcat
Copy link
Collaborator

@Nationalcat Nationalcat commented Nov 13, 2017

Translate eloquent-serialization.md (v5.5)

@Nationalcat Nationalcat changed the title Translate eloquent-serialization (v5.5) Translate eloquent-serialization.md (v5.5) Nov 13, 2017
@Nationalcat Nationalcat mentioned this pull request Nov 14, 2017
73 tasks
- [序列化成陣列](#serializing-to-arrays)
- [序列化成 JSON](#serializing-to-json)
- [從 JSON 隱藏屬性](#hiding-attributes-from-json)
- [附值到 JSON](#appending-values-to-json)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「附值」有點太濃縮 XD -> 「將值附加到 JSON」


When building JSON APIs, you will often need to convert your models and relationships to arrays or JSON. Eloquent includes convenient methods for making these conversions, as well as controlling which attributes are included in your serializations.
建構 JSON API 時,你經常會需要將模型和關聯轉換成陣列或 JSONEloquent 已包含了這些用來轉換的方便方法,以及控制序列化中應該包含哪些屬性。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eloquent 已經包含了這些用來轉換的方便方法,以及控制序列化中應該包含哪些屬性。

*
* @var array
*/
protected $hidden = ['password'];
}

> {note} When hiding relationships, use the relationship's method name.
> {note} 隱藏關聯時,請使用關聯的方法名稱。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

當隱藏關聯時,使用關聯方法名稱。

*
* @var array
*/
protected $visible = ['first_name', 'last_name'];
}

#### Temporarily Modifying Attribute Visibility
#### 暫時修改屬性的能見度
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

暫時修改屬性的可見性


return $user->makeHidden('attribute')->toArray();

<a name="appending-values-to-json"></a>
## Appending Values To JSON
## 附值到 JSON
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

將值附加到 JSON


Occasionally, when casting models to an array or JSON, you may wish to add attributes that do not have a corresponding column in your database. To do so, first define an [accessor](/docs/{{version}}/eloquent-mutators) for the value:
有時將模型轉換成陣列或 JSON 的時候,你可能希望在資料庫中新增沒有相應欄位的屬性。要達到此目的,首先為這個值定義 [存取器](/docs/{{version}}/eloquent-mutators)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

有時候,將模型轉換為陣列或JSON 時,你可能希望在資料庫中新增沒有相應欄位的屬性。要達到此目的,首先為這個值定義存取器

@neighborhood999 neighborhood999 merged commit aa6979b into laravel-taiwan:5.5 Dec 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants