Laravel 中 FormRequest 的验证消息

Validation message for FormRequest in Laravel

我有一个 FormRequest class 如下所示

    <?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 范围内一样。

谢谢

覆盖 StoreImageRequest.php 中的 messages() 方法。

public function messages()
{
    return [
            'uploadImage.mimes' => 'Custom error message.',
    ];
}

laravel 文档 here