mirror of
https://github.com/laravel/laravel.git
synced 2025-02-20 11:53:14 +08:00
update documentation.
This commit is contained in:
parent
71531e5fe9
commit
7d30d179b7
@ -29,5 +29,6 @@
|
|||||||
</div>
|
</div>
|
||||||
{{ HTML::script('http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js') }}
|
{{ HTML::script('http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js') }}
|
||||||
{{ HTML::script('laravel/js/prettify.js') }}
|
{{ HTML::script('laravel/js/prettify.js') }}
|
||||||
|
{{ HTML::script('laravel/js/scroll.js') }}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -269,7 +269,7 @@ code
|
|||||||
|
|
||||||
#toTop
|
#toTop
|
||||||
{
|
{
|
||||||
display:block;
|
display:none;
|
||||||
padding:0.2em 1em 0.05em 1em;
|
padding:0.2em 1em 0.05em 1em;
|
||||||
position:fixed;
|
position:fixed;
|
||||||
top:1.2em;
|
top:1.2em;
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
- [Constraining Eager Loads](#constraining-eager-loads)
|
- [Constraining Eager Loads](#constraining-eager-loads)
|
||||||
- [Setter & Getter Methods](#getter-and-setter-methods)
|
- [Setter & Getter Methods](#getter-and-setter-methods)
|
||||||
- [Mass-Assignment](#mass-assignment)
|
- [Mass-Assignment](#mass-assignment)
|
||||||
|
- [Converting Models To Arrays](#to-array)
|
||||||
|
|
||||||
<a name="the-basics"></a>
|
<a name="the-basics"></a>
|
||||||
## The Basics
|
## The Basics
|
||||||
@ -303,6 +304,10 @@ However, you may often only want to insert a new record into the intermediate ta
|
|||||||
|
|
||||||
$user->roles()->attach($role_id);
|
$user->roles()->attach($role_id);
|
||||||
|
|
||||||
|
Alternatively, you can use the `sync` method, which accepts an array of IDs to "sync" with the intermediate table. After this operation is complete, only the IDs in the array will be on the intermediate table.
|
||||||
|
|
||||||
|
$user->roles()->sync(array(1, 2, 3));
|
||||||
|
|
||||||
<a name="intermediate-tables"></a>
|
<a name="intermediate-tables"></a>
|
||||||
## Working With Intermediate Tables
|
## Working With Intermediate Tables
|
||||||
|
|
||||||
@ -457,4 +462,25 @@ Alternatively, you may use the **accessible** method from your model:
|
|||||||
|
|
||||||
User::accessible(array('email', 'password', 'name'));
|
User::accessible(array('email', 'password', 'name'));
|
||||||
|
|
||||||
> **Note:** Utmost caution should be taken when mass-assigning using user-input. Technical oversights could cause serious security vulnerabilities.
|
> **Note:** Utmost caution should be taken when mass-assigning using user-input. Technical oversights could cause serious security vulnerabilities.
|
||||||
|
|
||||||
|
<a name="to-array"></a>
|
||||||
|
## Converting Models To Arrays
|
||||||
|
|
||||||
|
When building JSON APIs, you will often need to convert your models to array so they can be easily serialized. It's really simple.
|
||||||
|
|
||||||
|
#### Convert a model to an array:
|
||||||
|
|
||||||
|
return json_encode($user->to_array());
|
||||||
|
|
||||||
|
The `to_array` method will automatically grab all of the attributes on your model, as well as any loaded relationships.
|
||||||
|
|
||||||
|
Sometimes you may wish to limit the attributes that are included in your model's array, such as passwords. To do this, add a `hidden` attribute definition to your model:
|
||||||
|
|
||||||
|
#### Excluding attributes from the array:
|
||||||
|
|
||||||
|
class User extends Eloquent {
|
||||||
|
|
||||||
|
public static $hidden = array('password');
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user