gpt4 book ai didi

php - 如何为多个输入字段设置单个自定义验证消息?

转载 作者:搜寻专家 更新时间:2023-10-31 21:49:13 24 4
gpt4 key购买 nike

public function rules(Request $request)
{
if ($request->isMethod('POST')) {
return [
"skill" => "required|array",
"skillyear.*" => "required_with:skill|numeric",
];
}
public function messages()
{
return [
'skill.required'=>'Select at least one skill',
'skillyear.*.required_with'=>"Experience year is required for the selected skill"
];}

所以,对于每个字段,我都会收到这样的消息 enter image description here我怎样才能得到所有这些的一条消息。

最佳答案

在 Controller 中使用简单的 laravel 验证:

    public function getRequest(Request $request) {

$this->validate($request, [
'param1' => 'required',
'param2' => 'required'
], [
'required' => 'Field is required'
], [
'param1' => 'field name 1 - message',
'param2' => 'field name 2 - message'
]);

更多:https://laravel.com/docs/5.5/validation

关于php - 如何为多个输入字段设置单个自定义验证消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47346430/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com