在哪里使用此代码中的限制?

Where to use the restriction in this code?

在这个控制器中,我将图像上传到数据库,但我该如何使用限制?我必须使用验证器吗?它应该是什么样子?

这是我的第一个项目,我开始使用 laravel 框架来获得学位。

namespace App\Http\Controllers\Autqwdh;



您可以对检查使用 Laravel 验证,其中 returns 一个 ErrorBag 包含您可以使用 in your blade.

的有意义的错误消息
$request->validate([
    'image' => 'image|max:5000'
]);

image 验证者:

The file under validation must be an image (jpeg, png, bmp, gif, or svg)

max 验证者:

The field under validation must be less than or equal to a maximum value. Strings, numerics, arrays, and files are evaluated in the same fashion as the size rule.

对于其他情况,请检查 Laravel Docs - Validation