Skip to content

Commit

Permalink
Document how to create a view without content
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Dec 21, 2024
1 parent 8b47f6b commit 1ee2514
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,18 @@ class Hello {
}
```

The above method routes will only accept `GET` requests. `POST` request methods can be annotated with `Post`, `PUT` with `Put`, and so on.
The above method routes will only accept `GET` requests. `POST` request methods can be annotated with `Post`, `PUT` with `Put`, and so on. To overwrite the method used for POST requests, pass the special `_method` field:

```html
<form action="/example" method="POST">
<input type="hidden" name="_method" value="PUT">
<!-- Rest of form -->
</form>
```

This will route the request as if it had been issued as `PUT /example HTTP/1.1`.

### Views

Route methods can return `web.frontend.View` instances to have more control over the response:

Expand All @@ -127,6 +138,9 @@ return View::named('hello')->with(['greet' => 'World']);
// Redirecting to either paths or absolute URIs
return View::redirect('/hello/World');

// No content
return View::empty()->status(204);

// Add headers and caching, here: for 7 days
return View::named('blog')
->with($article)
Expand All @@ -136,17 +150,6 @@ return View::named('blog')
;
```

To overwrite the method used for POST requests, pass the special `_method` field:

```html
<form action="/example" method="POST">
<input type="hidden" name="_method" value="PUT">
<!-- Rest of form -->
</form>
```

This will route the request as if it had been issued as `PUT /example HTTP/1.1`.

## Serving assets

Assets are delivered by the `AssetsFrom` handler as seen above. It takes care of content types, handling conditional and range requests for partial content, as well as compression.
Expand Down

0 comments on commit 1ee2514

Please sign in to comment.