之后我需要在控制器中验证请求吗?

问题描述 投票:0回答:0

我有这个StoreMessageRequest

public function rules(): array {
        return [
            'message' => [
                'required',
                'string',
                'max:60',
            ],
        ];
    }

导致 MessageController

public function store(StoreMessageRequest $request, Message $message) {
     ......
}

然后我可以运行查询

$message = new Message([
        'user_id' => auth()->id(),
        'message' => $request->message
    ]);

    $message->save($message);

这安全吗还是我应该使用

$request->safe()->message
~
$validated = $request->safe()->all();
$validated = $request->validated();

laravel laravel-validation
© www.soinside.com 2019 - 2024. All rights reserved.