formatting

This commit is contained in:
Taylor Otwell 2018-03-07 12:31:15 -06:00
parent a7f84ecba7
commit 6bb711d16a
1 changed files with 3 additions and 1 deletions

View File

@ -34,10 +34,12 @@ You may also convert entire [collections](/docs/{{version}}/eloquent-collections
<a name="serializing-to-json"></a>
### Serializing To JSON
To convert a model to JSON, you should use the `toJson` method. Like `toArray`, the `toJson` method is recursive, so all attributes and relations will be converted to JSON. An optional bitmask of options can be passed in as documented for PHP's [json_encode](http://php.net/manual/en/function.json-encode.php) function:
To convert a model to JSON, you should use the `toJson` method. Like `toArray`, the `toJson` method is recursive, so all attributes and relations will be converted to JSON. You may also specify JSON encoding options [supported by PHP](http://php.net/manual/en/function.json-encode.php):
$user = App\User::find(1);
return $user->toJson();
return $user->toJson(JSON_PRETTY_PRINT);
Alternatively, you may cast a model or collection to a string, which will automatically call the `toJson` method on the model or collection: