├── .babelrc ├── .gitignore ├── LICENSE ├── README.md ├── build.js ├── dist ├── vee-validate-laravel.js └── vee-validate-laravel.min.js ├── package-lock.json ├── package.json ├── src └── vee-validate-laravel.js └── types └── index.d.ts /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["env"] 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Robert Glyn Williams 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vee Validate for Laravel backend validation 2 | Simple vue js plugin that makes it easier to show validation errors from Laravel validation by using vee-validate. 3 | 4 | ### Getting Started 5 | 6 | In your script entry point: 7 | 8 | ```javascript 9 | import Vue from 'vue'; 10 | import VeeValidate from 'vee-validate'; 11 | import VeeValidateLaravel from 'vee-validate-laravel'; 12 | 13 | Vue.use(VeeValidate); 14 | Vue.use(VeeValidateLaravel); 15 | 16 | ``` 17 | 18 | From Laravel: 19 | 20 | ```php 21 | 22 | $request->validate([ 23 | 'name' => 'required|min:3|max:255' 24 | ]); 25 | 26 | 27 | ``` 28 | 29 | 30 | In Vue classes: 31 | 32 | 33 | ```vue 34 | 35 | 47 | 48 | 64 | 65 | ``` 66 | 67 | -------------------------------------------------------------------------------- /build.js: -------------------------------------------------------------------------------- 1 | import { rollup } from 'rollup'; 2 | import buble from 'rollup-plugin-buble'; 3 | import resolve from 'rollup-plugin-node-resolve'; 4 | import commonjs from 'rollup-plugin-commonjs'; 5 | import uglify from 'uglify-js'; 6 | import fs from 'fs'; 7 | import path from 'path'; 8 | import chalk from 'chalk'; 9 | import { version } from './package.json'; 10 | 11 | const banner = `/** 12 | * vee-validate-laravel v${version} 13 | */` 14 | 15 | const outputFolder = path.join(__dirname, 'dist'); 16 | 17 | const uglifyOptions = { 18 | compress: true, 19 | mangle: true 20 | }; 21 | 22 | const inputOptions = { 23 | input: 'src/vee-validate-laravel.js', 24 | plugins: [ 25 | resolve(), 26 | commonjs(), 27 | buble(), 28 | ], 29 | }; 30 | 31 | const outputOptions = { 32 | format: 'umd', 33 | name: 'VeeValidateLaravel', 34 | banner: banner, 35 | }; 36 | 37 | async function build () { 38 | console.log(chalk.cyan('Generating main builds...')); 39 | 40 | const bundle = await rollup(inputOptions); 41 | const { code } = await bundle.generate(outputOptions); 42 | 43 | fs.writeFileSync(path.join(outputFolder, 'vee-validate-laravel.js'), code); 44 | console.log(chalk.green('Output File:') + ' vee-validate-laravel.js'); 45 | 46 | fs.writeFileSync(path.join(outputFolder, 'vee-validate-laravel.min.js'), uglify.minify(code, uglifyOptions).code); 47 | console.log(chalk.green('Output File:') + ' vee-validate-laravel.min.js'); 48 | } 49 | 50 | build(); -------------------------------------------------------------------------------- /dist/vee-validate-laravel.js: -------------------------------------------------------------------------------- 1 | /** 2 | * vee-validate-laravel v1.0.1 3 | */ 4 | (function (global, factory) { 5 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : 6 | typeof define === 'function' && define.amd ? define(factory) : 7 | (global.VeeValidateLaravel = factory()); 8 | }(this, (function () { 'use strict'; 9 | 10 | var veeValidateLaravel = { 11 | install: function install(Vue, options) { 12 | Vue.prototype.$setLaravelValidationErrorsFromResponse = function(errorResponse) { 13 | var this$1 = this; 14 | 15 | // only allow this function to be run if the validator exists 16 | if (!this.hasOwnProperty('$validator')) { 17 | return; 18 | } 19 | 20 | // clear errors 21 | this.$validator.errors.clear(); 22 | 23 | // check if errors exist 24 | if (!errorResponse.hasOwnProperty('errors')) { 25 | return; 26 | } 27 | 28 | var errorFields = Object.keys(errorResponse.errors); 29 | 30 | // insert laravel errors 31 | for (var i = 0; i < errorFields.length; i++) { 32 | var field = errorFields[i]; 33 | 34 | var errorString = errorResponse.errors[field].join(', '); 35 | this$1.$validator.errors.add({ field: field, msg: errorString }); 36 | } 37 | }; 38 | 39 | Vue.prototype.$laravelData = {}; 40 | if (options) { 41 | Vue.prototype.$laravelData = options; 42 | } 43 | } 44 | }; 45 | 46 | return veeValidateLaravel; 47 | 48 | }))); 49 | -------------------------------------------------------------------------------- /dist/vee-validate-laravel.min.js: -------------------------------------------------------------------------------- 1 | !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):e.VeeValidateLaravel=r()}(this,function(){"use strict";return{install:function(e,r){e.prototype.$setLaravelValidationErrorsFromResponse=function(e){if(this.hasOwnProperty("$validator")&&(this.$validator.errors.clear(),e.hasOwnProperty("errors")))for(var r=Object.keys(e.errors),t=0;t