Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel's validator doesnt return input fields

problems with returning inputs. after form submitted, if validator fails it doesnt return 'old' inputs. here's my controller

$validator = Validator::make($request->all(), [
        'user_rate' => 'required|integer|between:1,5',
        'user_comment' => 'required',
    ], [
        "user_rate.integer" => trans('errors.rate-required'),
        "user_rate.between" => trans('errors.rate-required'),
        "user_rate.required" => trans('errors.rate-required'),
        "user_comment.required" => trans('errors.com-required'),

    ]);

    if ($validator->fails()) {
        return redirect()->back()->withErrors($validator)->withInput($request->input());
        //return redirect()->back()->with(Input::all());
    }

i have tried several ways(also $request->flash(), but it doesnt return 'old' inputs

like image 824
nooby Avatar asked Dec 25 '22 09:12

nooby


1 Answers

In your controller

public function someFunction(Request $request)
{
    //Validation Logic

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

In your view

<input type="text" name="some_name" value="{{old('some_name')}}">

Hope this helps.

like image 122
Dwijen Avatar answered Dec 28 '22 07:12

Dwijen