abu abu
abu abu

Reputation: 7052

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

Upvotes: 4

Views: 8648

Answers (1)

iamab.in
iamab.in

Reputation: 2070

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

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

laravel doc here

Upvotes: 9

Related Questions