【发布时间】:2019-04-17 00:59:35
【问题描述】:
我正在尝试在表单请求中为我的正则表达式显示自定义验证错误消息,到目前为止我还没有成功。
这是我的表单请求逻辑,正则表达式规则只接受字母和数字。
<?php
namespace App\Http\Requests\discounts;
use Illuminate\Foundation\Http\FormRequest;
class CheckoutCode extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'code' => 'required|string|min:7|max:7|regex:/([A-Za-z0-9 ])+/',
];
}
public function messages()
{
return [
'code.regex' => 'Estas jodido'
];
}
}
【问题讨论】: