1
votes

For Laravel 5.1 we know we can do validation by this way:

Validation using validate() method

$this->validate( $request, $rules);

Validation using Validator Facade

$validator = Validator::make($request->all(), $rules);
if($validator->fails()) {
  return redirect()->back()
    ->withInput($request->except('password'))
    ->withErrors($validator);
}

Does redirect back with errors with input required if I use validate() method ??

1

1 Answers

3
votes

Yes, Using $this->validate( $request, $rules) make the work for you redirecting the request if rules fails attaching the errors. In the other hand, using Validator:: makes you to implement a manual redirection.

I suggest you to use a Form Request class in order to keep your code clear and reusable.

class SignInRequest extends Request {

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'email' => array('required'),
        ];
    }
}

So, in your controller you can do:

function validateSignIn(SignInRequest $request){
    // do stuff here if rules are ok
}