nooby
nooby

Reputation: 294

Laravel doesnt show validation messages correctly

in my controller i have

public function store(Request $request) {
    $validator = Validator::make($request->all(), [
        "list_img" => "required",
        "ge_title" => "required|max:255"
    ]);

    if ($validator->fails()) {
        return redirect()->back()->withErrors($validator)->withInput();
    }

if validation fails i got messages -

validation.required

validation.required .....

instead of

ge_title is required

list_img is required

p.s. I have 3 languages on my site and i dont have validation.php file in resources/lang (if it matters)

Upvotes: 1

Views: 204

Answers (2)

Peter Kota
Peter Kota

Reputation: 8340

Try to add the third argument the error messages:

public function store(Request $request){
    $validator = Validator::make($request->all(), [
        "list_img" => "required",
        "ge_title" => "required|max:255"
    ], [
        "list_img.required" => "List img is required",
        "ge_title.required" => trans('errors.required'), //if you have multilang. then use trans function
        "ge_title.max" => trans('errors.max_title')
    ]);
    if ($validator->fails()){
        return redirect()->back()->withErrors($validator)->withInput();
    }
}

Upvotes: 1

Emy Ferreira
Emy Ferreira

Reputation: 851

It is not

$request->query->all()

instead of

$request->all()

for post or something like this ?

Upvotes: 1

Related Questions