我有一个FormRequest类,如下所示
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreImageRequest 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 [
'uploadImage' => 'image|mimes:jpg,png,jpeg,|max:2048',
];
}
}
如何在此处获取验证消息?就像文件不是Image
或文件大小不在max:2048
之内一样。
由于
答案 0 :(得分:1)
覆盖messages()
。{/ p>中的StoreImageRequest.php
方法
public function messages()
{
return [
'uploadImage.mimes' => 'Custom error message.',
];
}
laravel doc here