Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow parse expressions with Request::validate facade usage #31

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion laravel/documenting/50-query-body-parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ These two approaches are very different:
:::note
Form requests are not initialized by Scribe in the same way as Laravel would, since there is no real HTTP request when generating. If you encounter strange behaviour, you can try customising the initialization process with the [`instantiateFormRequestUsing()` hook](/laravel/hooks#instantiateformrequestusing).
:::
- With inline validators, Scribe will read and parse the validation code in your controller (`$request->validate()` or `Validator::make()`).
- With inline validators, Scribe will read and parse the validation code in your controller (`$request->validate()`, `Request::validate` or `Validator::make()`).

Since these rules only describe validation logic, Scribe allows you to provide extra information, like a description and example:
- For form requests, add a `bodyParameters()`/`queryParameters()` method where you can add a description and example for each parameter.
Expand All @@ -295,6 +295,7 @@ If you have rules that Scribe doesn't support, Scribe's generated value might no
defaultValue="inline-validate"
values={[
{label: 'Inline ($request->validate())', value: 'inline-validate'},
{label: 'Inline (Request::validate())', value: 'inline-validate-facade'},
{label: 'Inline (Validator::make())', value: 'inline-manual'},
{label: 'Form request', value: 'formrequest'},
]}>
Expand Down Expand Up @@ -324,6 +325,33 @@ public function createPost($request)
}
```

</TabItem>
<TabItem value="inline-validate-facade">

```php
public function createPost($request)
{
$validated = Request::validate([
// Contents of the post
'content' => 'string|required|min:100',
// The title of the post. Example: My First Post
'title' => 'string|required|max:400',
'author_display_name' => 'string',
'author_homepage' => 'url',
'author_timezone' => 'timezone',
'author_email' => 'email|required',
// Date to be used as the publication date.
'publication_date' => 'date_format:Y-m-d',
// Category the post belongs to.
'category' => ['in:news,opinion,quiz', 'required'],
// This will be included in docs but not in examples. No-example
'extra' => 'string',
]);

return Post::create($validated);
}
```

</TabItem>
<TabItem value="inline-manual">

Expand Down