Updated documentation

This commit is contained in:
Simon Sessingø
2021-03-29 22:04:46 +02:00
parent 438193ef59
commit 5621ffc724

View File

@@ -48,7 +48,6 @@ You can donate any amount of your choice by [clicking here](https://www.paypal.c
- [Namespaces](#namespaces)
- [Subdomain-routing](#subdomain-routing)
- [Route prefixes](#route-prefixes)
- [Partial groups](#partial-groups)
- [Form Method Spoofing](#form-method-spoofing)
- [Accessing The Current Route](#accessing-the-current-route)
- [Other examples](#other-examples)
@@ -631,6 +630,23 @@ SimpleRouter::group(['namespace' => 'Admin'], function () {
});
```
You can add parameters to the prefixes of your routes.
Parameters from your previous routes will be injected
into your routes after any route-required parameters, starting from oldest to newest.
```php
SimpleRouter::group(['prefix' => '/lang/{lang}'], function ($language) {
SimpleRouter::get('/about', function($language) {
// Will match /lang/da/about
});
});
```
### Subdomain-routing
Route groups may also be used to handle sub-domain routing. Sub-domains may be assigned route parameters just like route urls, allowing you to capture a portion of the sub-domain for usage in your route or controller. The sub-domain may be specified using the `domain` key on the group attribute array:
@@ -665,29 +681,6 @@ SimpleRouter::group(['prefix' => '/lang/{language}'], function ($language) {
});
```
## Partial groups
Partial router groups has the same benefits as a normal group, but supports parameters and are only rendered once the url has matched.
Partial groups will render once a part of the url has matched.
This can be extremely useful in situations, where you only want special routes to be added, when a certain criteria or logic has been met.
**NOTE:** Use partial groups with caution as routes added within are only rendered and available once the url of the partial-group has matched. This can cause `url()` not to find urls for the routes added within.
**Example:**
```php
SimpleRouter::partialGroup('/lang/{language}', function ($language) {
SimpleRouter::get('/', function($language) {
// Matches The "/lang/da" URL
});
});
```
## Form Method Spoofing
HTML forms do not support `PUT`, `PATCH` or `DELETE` actions. So, when defining `PUT`, `PATCH` or `DELETE` routes that are called from an HTML form, you will need to add a hidden `_method` field to the form. The value sent with the `_method` field will be used as the HTTP request method: