Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display error messages in redirect function with form request validation using laravel 5

I am validating form with formRequest, I have defined $redirect. Now I want to handle validation error in $redirect function.

like image 428
user2893940 Avatar asked Oct 20 '22 13:10

user2893940


1 Answers

I am able to create the json with error message from formRequest but without $redirect.

Here is my code,

<?php 
namespace App\Http\Requests;
use App\Http\Requests\Request;
use Response;
class CreateUserRequest extends Request {

    /**
    * 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 [
            'email' => 'required'
        ];
    }
    public function messages(){
        return [
            'email.required' => 'Er, you forgot your email address!'
        ];
    }

    public function response(array $errors)
    {

        return Response::json($errors, 400);
    }
}
like image 140
user2893940 Avatar answered Oct 22 '22 21:10

user2893940