Skip to content

Commit

Permalink
📝 added example for validation custom attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianmieller committed Feb 15, 2023
1 parent 38b4043 commit 89adbe8
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ Add the trait
use acidjazz\metapi\MetApi;
class Controller
{
use Metapi;
use Metapi;
```

## Examples
## Examples

```php
<?php
Expand Down Expand Up @@ -112,3 +112,41 @@ bob({
{
```

**Add [custom attributes](https://laravel.com/docs/9.x/validation#specifying-custom-attribute-values) to validation.**

```php
public function send(Request $request)
{
$this->option('contact.email', 'required|email', [], 'Email Address')
->option('contact.name', 'required|string', [], 'Firstname')
->option('contact.surname', 'required|string', [], 'Lastname')
->verify();
...
$this->render($results);
}
```

`POST /send`

```json
{
"status": "error",
"errors": [
{
"status": 400,
"message": "contact.email",
"detail": "Email Address is a required field."
},
{
"status": 400,
"message": "contact.name",
"detail": "Firstname is a required field."
},
{
"status": 400,
"message": "contact.surname",
"detail": "Lastname is a required field."
}
]
}
```

0 comments on commit 89adbe8

Please sign in to comment.