Skip to content

Commit

Permalink
Document Response::macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Dec 9, 2013
1 parent 0e2c5b1 commit 65148c1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [Views](#views)
- [View Composers](#view-composers)
- [Special Responses](#special-responses)
- [Response Macros](#response-macros)

<a name="basic-responses"></a>
## Basic Responses
Expand Down Expand Up @@ -192,4 +193,20 @@ View **creators** work almost exactly like view composers; however, they are fir

return Response::download($pathToFile, $name, $headers);

> **Note:** Symfony HttpFoundation, which manages file downloads, requires the file being downloaded to have an ASCII file name.
> **Note:** Symfony HttpFoundation, which manages file downloads, requires the file being downloaded to have an ASCII file name.
<a name="response-macros"></a>
## Response Macros

If you would like to define a custom response that you can re-use in a variety of your routes and controllers, you may use the `Response::macro` method:

Response::macro('caps', function($value)
{
return Response::make(strtoupper($value));
});

The `macro` function accepts a name as its first argument, and a Closure as its second. The macro's Closure will be executed when calling the macro name on the `Response` class:

return Response::caps('foo');

You may define your macros in one of your `app/start` files. Alternatively, you may organize your macros into a separate file which is included from one of your `start` files.

0 comments on commit 65148c1

Please sign in to comment.