3 years ago

How to return validation errors as JSON to view

Posted 3 years ago by MrRobot21

Hi awesome people

i'm building an API, i'm validating the input fields in my StoreLesson.php

    public function rules()
        return [
            'title' => 'required',
            'body' => 'required',

i'm using postman to test the API, things are working fine but when i send POST request with empty fields in postman console in webview i'm getting redirected to welcom.blade.php

    public function store(StoreLessons $request) 

        return response()->json($validator->errors(), 422);  //i'm not getting any json with errors


        return $this->respondCreated('Lesson created successfully');

i want to display the validator error as json

thank You

Please sign in or create an account to participate in this conversation.