1

as i can see in my blade like

@if ($errors->has('email')) <span class="invalid-feedback"> <strong>{{ $errors->first('email') }}</strong> </span> @endif 

i want to set errors so that $error variable will contain error message i know in this case its getting error from default suppose want to show custom error message to the $error variable how to do that and i have not passed that variable to the blade still it has access can u please tell me short working of that sorry but i am new to laravel

3
  • have you try the Laravel error handler ? laravel.com/docs/5.6/errors Commented Mar 15, 2018 at 8:49
  • You could set custom error messages, by passing the messages as third argument to the Validator. Check out the documentation here .The $errors variable is flashed to session and is automatically made available to all views by laravel. Commented Mar 15, 2018 at 8:53
  • try changing error message in resources->lang->en->validation.php->'email' => 'The :attribute must be a valid email address.' to 'email'=>'your custom error message.' Commented Mar 15, 2018 at 8:56

1 Answer 1

2

Use withErrors() method to redirect with error message and pass your custom error message array as third parameter in make() method.

$messages = [ 'email.required' => 'Your custom error message', ]; $rules = [ 'email' => 'required|email|unique:users', ]; $validator=Validator::make(Input::all(),$rules,$messages); if($validator->fails()){ return redirect()->back()->withErrors($validator)->withInput(); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.