2

I'm using laravel 9 and Vue 3. I am trying to access laravel validation error in vue. Error message send by laravel.

{message: "The given data was invalid.",…}
errors: {supplyData.supplier_id: ["Please fill the supplier field"]}
supplyData.supplier_id: ["Please fill the supplier field"]
0: "Please fill the supplier field"
message: "The given data was invalid."

I have tried following code to access the error but it didn't work.

  <span
                    v-if="errors['supplyData.supplier_id']"
                   
                    class="invalid_feedback"
                    style="display:block; color:red;"
                    role="alert"
                >
                   {{ errors["supplyData.supplier_id"][0]}}
   </span>
6
  • Where is the errors coming from is it coming from an axios call? Commented Mar 4, 2022 at 6:00
  • yeah. And in backend i am using laravel validation. Commented Mar 4, 2022 at 6:02
  • can you show your api call and handling @WhoDoYouthinkami Commented Mar 4, 2022 at 6:04
  • should i comment it or update the question? Commented Mar 4, 2022 at 6:05
  • Update it please. And can you share your response from backend Commented Mar 4, 2022 at 6:05

1 Answer 1

1

If you check your console to see what is the real response from laravel backend, you probably see it is inside of data object,

Let's assume you have axios call like store()..

After this store request the data you got is response. The error is inside data of this response.

You can probably reach it like: response.data.errors

        .catch(error => {
            this.errors = error.response.data.errors; // this should be errors.
             console.log(this.errors);
        });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.