npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

laravel-veevalidate

v1.3.1

Published

The super simple JS package that'll translate your Laravel Validation errors into VeeValidate errors. ✨

Downloads

19

Readme

🚨 Laravel VeeValidate

The super simple JS package that will handle your Laravel errors and automatically inject them into a VeeValidate instance ✨

Example Image

Installation

npm i laravel-veevalidate

or

yarn add laravel-veevalidate

Usage

Assuming you already have VeeValidate installed, you can use Laravel VeeValidate as a Vue Prototype.

import LaravelValidator from 'laravel-veevalidate';

Vue.prototype.$laravelValidator = LaravelValidator;

Alternatively, you can use it on a on a component-to-component basis.

import LaravelValidator from 'laravel-veevalidate';

Using it from with Axios

To use the error handler with Axios, you will need to place the handleError method inside of the catch() block of the Axios promise.

The first parameter you must provide is the VeeValidate instance you would like to use. It's recommended to use the global directive ($validator). The second parameter is the response callback which Axios provides.

axios(...)
    .catch(error_response => {
       this.$laravelValidator.handleError(this.$validator, error_response) 
    })

Using it with Fetch

To use the error handler with Fetch, you will need to place the handleFetchError method inside of the then() block of the Fetch promise.

The first parameter you must provide is the VeeValidate instance you would like to use. It's recommended to use the global directive ($validator). The second parameter is the response callback which Fetch provides.

fetch(...)
    .then(response => {
       this.$laravelValidator.handleFetchError(this.$validator, response) 
    })

Clearing Errors

Important: Laravel VeeValidate does not clear your VeeValidate errors. Before your request you should clear the error bag from your VeeValidate Instance:

// e.g: 
this.$validator.errors.clear();

Custom field mapping

Sometimes your Request/Eloquent attributes won't match your VeeValidate fields/names. You can really easily "map" this by passing a key value object as a third parameter.

    // Axios
    this.$laravelValidator.handleError(this.$validator, error_response, {
           'email_address': 'email address', // Attribute => Field Name
       }) 
    })
    
    // Fetch
    this.$laravelValidator.handleFetchError(this.$validator, response, {
           'email_address': 'email address', // Attribute => Field Name
       }) 
    })

Options

Laravel VeeValidate provides some simple options which you can pass as the fourth parameter of the handleError and handleFetchError methods.

| Option | Description | Type | Default Value | Choices | | ------------- |-------------| :-----:| :-------------:|------------| | driver | Request driver you are using. | String | axios | axios fetch | | show_errors | Display console errors while in Development mode | Boolean | true | true false |

Applying an option

this.$laravelValidator.handleError(this.$validator, error_response, {}, {
    show_errors: false
}) 

And that's it! ✨

This is my first JS/NPM package, I really hope it's been useful to you, if you like my work and want to show some love, consider buying me some coding fuel (Coffee) ❤

https://ko-fi.com/sammyjo20