Skip to content

Commit ebc7163

Browse files
authored
Merge pull request #31 from geangontijo/patch-1
Allow parse expressions with Request::validate facade usage
2 parents d650d4c + e988a2f commit ebc7163

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

Diff for: laravel/documenting/50-query-body-parameters.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ These two approaches are very different:
277277
:::note
278278
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).
279279
:::
280-
- With inline validators, Scribe will read and parse the validation code in your controller (`$request->validate()` or `Validator::make()`).
280+
- With inline validators, Scribe will read and parse the validation code in your controller (`$request->validate()`, `Request::validate` or `Validator::make()`).
281281

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

328+
</TabItem>
329+
<TabItem value="inline-validate-facade">
330+
331+
```php
332+
public function createPost($request)
333+
{
334+
$validated = Request::validate([
335+
// Contents of the post
336+
'content' => 'string|required|min:100',
337+
// The title of the post. Example: My First Post
338+
'title' => 'string|required|max:400',
339+
'author_display_name' => 'string',
340+
'author_homepage' => 'url',
341+
'author_timezone' => 'timezone',
342+
'author_email' => 'email|required',
343+
// Date to be used as the publication date.
344+
'publication_date' => 'date_format:Y-m-d',
345+
// Category the post belongs to.
346+
'category' => ['in:news,opinion,quiz', 'required'],
347+
// This will be included in docs but not in examples. No-example
348+
'extra' => 'string',
349+
]);
350+
351+
return Post::create($validated);
352+
}
353+
```
354+
327355
</TabItem>
328356
<TabItem value="inline-manual">
329357

0 commit comments

Comments
 (0)