Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation message for FormRequest in Laravel

I have a FormRequest class like below

    <?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',
        ];
    }
}

How can I get validation message here ? Like if the file is not an Image or the file size is not within max:2048.

Thanks

like image 877
abu abu Avatar asked Sep 03 '25 09:09

abu abu


1 Answers

override the messages() method in the StoreImageRequest.php.

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

laravel doc here

like image 192
iamab.in Avatar answered Sep 05 '25 00:09

iamab.in