# 手动验证

如果你不在控制器内工作,或者其他原因，你可以手动创建Validator facade实例，然后检查成功或者失败，如示例7-14

{% code title="Example 7-14. Manual validation" %}

```php
Route::get('recipes/create', function () { 
    return view('recipes.create');
});

Route::post('recipes', function (Illuminate\Http\Request $request) {
    $validator = Validator::make($request->all(), [
        'title' => 'required|unique:recipes|max:125',
        'body' => 'required'
    ]);
    if ($validator->fails()) {
        return redirect('recipes/create')
            ->withErrors($validator)
            ->withInput();
    }
    // Recipe is valid; proceed to save it
});
```

{% endcode %}

如看到的，我们创建了一个验证实例，将输入当做第一个参数，验证规则当第二个参数，验证对象公开了一个fails()方法，用于检测验证,然后可以将验证实例传递给withErrors()


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://liseen315.gitbook.io/laravel/shou-ji-he-chu-li-yong-hu-shu-ju/yan-zheng/shou-dong-yan-zheng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
