├── .bowerrc ├── .editorconfig ├── .gitignore ├── .mversionrc ├── .npmignore ├── .scrutinizer.yml ├── .travis.yml ├── Gruntfile.js ├── LICENSE.md ├── README.md ├── bower.json ├── build.xml ├── composer.json ├── config └── laraval.php ├── docgen.json ├── docs ├── basic-usage.md ├── bootstrap3-style.md ├── index.md ├── installation.md ├── javascript-api.md ├── menu.yml ├── structure.xml └── validation-strategies.md ├── package.json ├── phpunit.xml ├── resources ├── assets │ ├── demo.d.ts │ ├── demo.scss │ ├── demo.ts │ ├── demo │ │ ├── @init.ts │ │ ├── JSON.ts │ │ ├── font-awesome.ts │ │ └── form.ts │ ├── index.html │ ├── jquery.validate.laravel.d.ts │ ├── jquery.validate.laravel.dev.d.ts │ ├── jquery.validate.laravel.ts │ ├── lib │ │ ├── @init.ts │ │ ├── messages.ts │ │ ├── php.ts │ │ ├── validator.ts │ │ └── ~bootstrap.ts │ ├── localization │ │ └── messages_nl.js │ ├── types.d.ts │ └── types │ │ ├── jquery.validation.d.ts │ │ └── vendor │ │ ├── highlightjs │ │ └── highlightjs.d.ts │ │ ├── jquery.slimScroll │ │ └── jquery.slimScroll.d.ts │ │ ├── jquery │ │ └── jquery.d.ts │ │ ├── jqueryui │ │ └── jqueryui.d.ts │ │ └── tsd.d.ts └── views │ ├── create.blade.php │ ├── demo.blade.php │ ├── demo │ ├── ajax.blade.php │ ├── form-builder.blade.php │ ├── input.blade.php │ ├── layout.blade.php │ └── local.blade.php │ ├── index.html │ └── init.blade.php ├── run ├── src ├── Contracts │ └── Factory.php ├── Facades │ └── Laraval.php ├── Factory.php ├── Http │ ├── Controllers │ │ └── Demo │ │ │ ├── AjaxDemoController.php │ │ │ ├── DemoController.php │ │ │ ├── FormBuilderDemoController.php │ │ │ ├── LocalDemoController.php │ │ │ └── macros.php │ └── routes.php ├── LaravalServiceProvider.php ├── Providers │ └── RouteServiceProvider.php └── Strategies │ ├── AjaxValidationStrategy.php │ ├── LocalValidationStrategy.php │ └── ValidationStrategy.php └── tsd.json /.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "resources/assets/vendor", 3 | "analytics": false 4 | } 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | 10 | # Change these settings to your own preference 11 | indent_style = space 12 | indent_size = 4 13 | 14 | # We recommend you to keep these unchanged 15 | end_of_line = lf 16 | charset = utf-8 17 | trim_trailing_whitespace = true 18 | insert_final_newline = true 19 | 20 | [*.md] 21 | trim_trailing_whitespace = false 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store 5 | /resources/assets/vendor 6 | /node_modules 7 | /lib 8 | /.tscache 9 | /.sass-cache 10 | /gh-pages 11 | -------------------------------------------------------------------------------- /.mversionrc: -------------------------------------------------------------------------------- 1 | { 2 | "commitMessage": "Bumped to %s", 3 | "tagName": "%s", 4 | "scripts": { 5 | "preupdate": "echo 'Bumping version' && sh ./run preupdate", 6 | "postcommit": "sh ./run postcommit && echo 'Post commit executed'", 7 | "postupdate": "echo 'Updated to version %s in manifest files'" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | config 3 | resources/views 4 | src 5 | tests 6 | .scrutinizer.yml 7 | .travis.yml 8 | build.xml 9 | composer.json 10 | phpunit.xml 11 | run 12 | .tscache 13 | .sass-cache 14 | .mversionrc 15 | bower.json 16 | .bowerrc 17 | .editorconfig 18 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | tools: 2 | php_sim: true 3 | php_pdepend: true 4 | php_analyzer: true 5 | external_code_coverage: true 6 | php_code_sniffer: 7 | config: 8 | standard: "PSR2" 9 | filter: 10 | excluded_paths: 11 | - 'tests/*' 12 | - 'vendor/*' 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | php: 6 | - 5.5 7 | - 5.6 8 | - hhvm 9 | 10 | before_script: 11 | - composer self-update 12 | - composer install --prefer-source --no-interaction 13 | 14 | script: phpunit -c phpunit.xml --coverage-clover=coverage.clover 15 | 16 | after_script: 17 | - wget https://scrutinizer-ci.com/ocular.phar 18 | - php ocular.phar code-coverage:upload --format=php-clover coverage.clover 19 | 20 | 21 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | var path = require('path'), 2 | util = require('util'), 3 | fs = require('fs'); 4 | 5 | var grunt = require('grunt'); 6 | 7 | 8 | 9 | module.exports = function (_grunt) { 10 | grunt = _grunt; 11 | 12 | function asset(file) { 13 | return path.join('resources', 'assets', file); 14 | } 15 | 16 | var vfile = asset('jquery.validate.laravel'); 17 | var demoTsSrc = [ 18 | asset('demo/@init.ts'), 19 | asset('demo/**/*.ts'), 20 | asset('demo.ts') 21 | ]; 22 | var tsSrc = [ 23 | asset('lib/@init.ts'), 24 | asset('lib/php.ts'), 25 | asset('lib/validator.ts'), 26 | //asset('lib/mimes.ts'), 27 | asset('lib/messages.ts'), 28 | vfile + '.ts', 29 | asset('lib/~bootstrap.ts') 30 | ]; 31 | var schemaPath = asset('demo-data.json'); 32 | 33 | var config = { 34 | target : { 35 | vfile: vfile, 36 | asset: asset 37 | }, 38 | umd : { 39 | validator: { 40 | src : vfile + '.js', dest: vfile + '.js', //objectToExport: '$', //globalAlias: 'jquery', 41 | deps: { 42 | 'default': ['$'], 43 | amd : ['jquery'], 44 | cjs : ['jquery'], 45 | global : [{jQuery: '$'}] 46 | } 47 | } 48 | }, 49 | copy: { 50 | docdemo: { cwd: 'resources/assets', src: ['demo.{css,js}', 'demo-data.json', 'jquery.validate.laravel.js', 'index.html'], dest: 'gh-pages/demo/', expand: true} 51 | }, 52 | sass : { 53 | options: {sourcemap: true, style: 'expanded'}, 54 | demo : {files: {'<%= target.asset("demo.css") %>': '<%= target.asset("demo.scss") %>'}} 55 | }, 56 | uglify : { 57 | validator: {files: {'<%= target.vfile %>.min.js': ['<%= target.vfile %>.js']}} 58 | }, 59 | bytesize: {validator: {src: [vfile + '.min.js', vfile + '.js']}}, 60 | ts : { 61 | options: {compiler: './node_modules/.bin/tsc', module: 'commonjs', experimentalDecorators: true, target: 'es5', declaration: false, sourceMap: true}, 62 | demo : {options: {declaration: true}, src: demoTsSrc, out: asset('demo.js')}, 63 | dev : {options: {declaration: true}, src: tsSrc, out: vfile + '.dev.js'}, 64 | dist : {options: {sourceMap: false}, src: tsSrc, out: vfile + '.js'} 65 | }, 66 | typedoc : { 67 | options : {target: 'es5', mode: 'file', hideGenerator: '', experimentalDecorators: '', includeDeclarations: '', readme: 'README.md'}, 68 | validator: { 69 | options: {out: 'docs/jquery.validate.laravel', name: 'Laravel jQuery Validator API Documentation', ignoreCompilerErrors: ''}, //readme: 'docs/packadic.md', excludeExternals: '', 70 | src : ['resources/assets/**/*.ts', '!resources/assets/jquery.validate.laravel.d.ts'] 71 | } 72 | }, 73 | watch : { 74 | options : {livereload: true}, 75 | umd_uglify: {files: [vfile + '.js'], tasks: ['umd:validator', 'uglify:validator']}, 76 | ts : {files: [vfile + '.ts', asset('lib/**/*.ts')], tasks: ['ts:dev']}, 77 | ts_demo : {files: demoTsSrc, tasks: ['ts:demo']}, 78 | sass : {files: [asset('demo.scss')], tasks: ['sass:demo']} 79 | } 80 | }; 81 | 82 | require('time-grunt')(grunt); 83 | require('load-grunt-tasks')(grunt); 84 | grunt.initConfig(config); 85 | 86 | 87 | [ 88 | ['build:dev', 'Build dev version', ['ts:dev', 'umd:validator']], 89 | ['build:demo', 'Build demo stuff', ['ts:demo', 'sass:demo']], 90 | ['build', 'Build all', ['build:dev', 'build:demo']], 91 | ['dist', 'Build dist version', ['ts:dist', 'umd:validator', 'uglify:validator']], 92 | ['default', 'Default task (build)', ['build']] 93 | ].forEach(function (task) { 94 | grunt.registerTask(task[0], task[1], task[2]); 95 | }) 96 | } 97 | ; 98 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015, Caffeinated 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Laravel logo](http://laravel.com/assets/img/laravel-logo.png) Laraval 2 | ======================== 3 | 4 | Laravel 5 jQuery form validation using Laravel's Validator rules. Client & Server(AJAX) validation strategies. 5 | 6 | [![License](http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://tldrlegal.com/license/mit-license) 7 | 8 | - You can use the `javascript` library stand-alone. The provided PHP library is optional. 9 | - Stand alone can **not** use the `database` validation rules. 10 | - Error messages can be imported straight from your `Application`'s language files. 11 | - The `Laraval` PHP library provides more then a few conveinence methods. It also provides the logic for `AJAX` validation, which enables *all* validation rule methods. 12 | - Depends on `jQuery` and [`jquery.validate`](http://jqueryvalidation.org) JS libraries. 13 | - Multimple demos (local, ajax, etc) provided using Bootstrap 3. 14 | 15 | The package follows the FIG standards PSR-1, PSR-2, and PSR-4 to ensure a high level of interoperability between shared PHP code. 16 | 17 | 18 | [**Documentation**](http://robin.radic.nl/laraval) 19 | 20 | [**Demonstration**](http://robin.radic.nl/laraval) 21 | 22 | 23 | 24 | Quick Impression 25 | ------------- 26 | 27 | ``` 28 | jquery.validate.laravel.min.js 29 | Size: 16.01 Kb 30 | Gzip Size: 4.79 Kb 31 | ``` 32 | 33 | ### Client side 34 | 35 | 36 | By including the `jquery.validate.js` & `jquery.validate.laraval.js` you will be able to use Laravel's (5.x) validation rules like this: 37 | 38 | ```html 39 | 44 | ``` 45 | 46 | ### Local example 47 | ```php 48 | $rules = [ 49 | 'title' => 'required|max:15|alpha_num', 50 | 'body' => 'required|max:255|alpha_dash', 51 | 'between_dates' => 'after:1/1/2000|before:1/1/2010|date', 52 | 'user_email' => 'required|email', 53 | 'url' => 'required|url', 54 | 'is_admin' => 'boolean', 55 | 'active' => 'boolean' 56 | ]; 57 | return View::make('myview', [ 58 | 'rules' => $rules 59 | ]); 60 | ``` 61 | view: 62 | ```html 63 |
64 | 65 | 66 |
67 | {{ Laraval::local('#demo-form', $rules) }} 68 | ``` 69 | 70 | ### AJAX example 71 | ```php 72 | Route::post('validate', function(Request $request){ 73 | $rules = [ 74 | 'title' => 'required|max:15|alpha_num', 75 | 'body' => 'required|max:255|alpha_dash', 76 | 'between_dates' => 'after:1/1/2000|before:1/1/2010|date' 77 | ] 78 | return Laraval::make('ajax', $rules)->validate($request); 79 | }); 80 | ``` 81 | view: 82 | ```html 83 |
84 | 85 | 86 | 87 |
88 | {{ Laraval::ajax('#demo-form', [ 'url' => url('validate') ]) }} 89 | ``` 90 | 91 | 92 | ### Copyright/License 93 | Copyright 2015 [Robin Radic](https://github.com/RobinRadic) - [MIT Licensed](http://radic.mit-license.org) 94 | 95 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laraval", 3 | "version": "1.0.0", 4 | "authors": [ 5 | "Robin Radic " 6 | ], 7 | "license": "MIT", 8 | "main": [ 9 | "resources/assets/jquery.validate.laravel.min.js" 10 | ], 11 | "ignore": [ 12 | "**/.*", 13 | "node_modules", 14 | "bower_components", 15 | "docs", 16 | "lib", 17 | "src", 18 | "test", 19 | "tests", 20 | "resources/assets/**/*.dev*", 21 | "resources/assets/data.json", 22 | "resources/assets/vendor", 23 | "resources/views", 24 | "resources/assets/demo*", 25 | ".editorconfig", 26 | ".gitignore", 27 | ".mversionrc", 28 | ".scrutinizer.yml", 29 | ".travis.yml", 30 | "build.xml", 31 | "composer.json", 32 | "phpunit.xml", 33 | "run" 34 | ], 35 | "devDependencies": { 36 | "jquery": "2.1.4", 37 | "jquery.validate": "1.13.0", 38 | "jquery-form": "3.46.0", 39 | "jquery-mockjax": "2.0.1", 40 | "bootstrap": "3.3.5", 41 | "jquery-ui": "1.11.4", 42 | "highlightjs": "8.8.0", 43 | "lodash": "3.10.1", 44 | "jquery.slimscroll": "1.3.6" 45 | }, 46 | "dependencies": { 47 | "bootswatch": "3.3.5+4" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "radic/laraval", 3 | "description": "Laravel 5 jQuery Validation. Full client side, full AJAX, hybrid and other modes. Bootstrap and other frameworks supported.", 4 | "authors": [ 5 | { 6 | "name": "Robin Radic", 7 | "email": "test@email.nl", 8 | "homepage": "https://github.com/robinradic" 9 | } 10 | ], 11 | "require": { 12 | "php": ">=5.5.9", 13 | "sebwite/support": "1.0.*|2.0.*" 14 | }, 15 | "suggest": { 16 | "laravelcollective/html": "Laraval provides several extensions based on the Form builders from Laravel Collective. Easy form building with awesome validation!" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "Radic\\Laraval\\": "src/" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /config/laraval.php: -------------------------------------------------------------------------------- 1 | env('RADIC_LARAVAL_DEMO', false), 5 | 'strategies' => [ 6 | 'local' => \Radic\Laraval\Strategies\LocalValidationStrategy::class, 7 | 'ajax' => \Radic\Laraval\Strategies\AjaxValidationStrategy::class 8 | ], 9 | 'client_defaults' => [ 10 | 'enabled' => true, 11 | 'strategy' => 'local', 12 | 'dataAttribute' => 'laraval', 13 | 'url' => '', 14 | 'crsfTokenKey' => '_token' 15 | ] 16 | ]; 17 | -------------------------------------------------------------------------------- /docgen.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Laraval documentation", 3 | "logo": { 4 | "text": "Laraval", 5 | "size": 25, 6 | "x": 0, 7 | "y": 0 8 | }, 9 | "copyright": "Copyright 2015 © Robin Radic", 10 | "docs": "docs", 11 | "dest": "gh-pages", 12 | "index": "docs/index.md", 13 | "generators": { 14 | "typedoc": { 15 | "laraval": { 16 | "files": [ 17 | "resources/assets/{lib,types}/**/*.ts", 18 | "resources/assets/jquery.validate.laravel.ts" 19 | ], 20 | "options": { 21 | "name": "Scripting API", 22 | "module": "commonjs", 23 | "rootDir": "./", 24 | "target": "es5", 25 | "mode": "file", 26 | "experimentalDecorators": "", 27 | "entryPoint": "laraval", 28 | "readme": "docs/javascript-api.md" 29 | } 30 | } 31 | } 32 | }, 33 | "menu": [ 34 | { 35 | "name": "Home", 36 | "type": "index", 37 | "icon": "fa fa-home" 38 | }, 39 | {"name": "Documentation", "type": "heading"}, 40 | { 41 | "name": "Installation", 42 | "doc": "installation.md", 43 | "type": "doc", 44 | "icon": "fa fa-archive" 45 | }, 46 | { 47 | "name": "Basic usage", 48 | "doc": "basic-usage.md", 49 | "type": "doc", 50 | "icon": "fa fa-ambulance" 51 | }, 52 | { 53 | "name": "Validation strategies", 54 | "doc": "validation-strategies.md", 55 | "type": "doc", 56 | "icon": "fa fa-book" 57 | }, 58 | {"name": "API", "type": "heading"}, 59 | { 60 | "name": "Javascript", 61 | "typedoc": "laraval", 62 | "type": "typedoc", 63 | "icon": "fa fa-code color-red-700" 64 | }, 65 | { 66 | "name": "PHP", 67 | "href": "#", 68 | "type": "href", 69 | "icon": "fa fa-code color-green-700" 70 | }, 71 | {"name": "Miscellaneous", "type": "heading"}, 72 | { 73 | "name": "Bootstrap 3 style", 74 | "doc": "bootstrap3-style.md", 75 | "type": "doc", 76 | "icon": "fa fa-paint-brush" 77 | }, 78 | { 79 | "name": "Demonstration", 80 | "href": "http://robin.radic.nl/laraval/demo/index.html", 81 | "type": "href", 82 | "icon": "fa fa-play-circle-o" 83 | }, 84 | { 85 | "name": "Github", 86 | "href": "https://github.com/robinradic/laraval", 87 | "type": "href", 88 | "icon": "fa fa-github" 89 | } 90 | ] 91 | } 92 | -------------------------------------------------------------------------------- /docs/basic-usage.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Basic usage 3 | author: Robin Radic 4 | --- 5 | 6 | ### Basic client-side only 7 | Laraval can be used in many ways. Lets start with a basic client-side only example: 8 | 9 | ```html 10 |
11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | {{ Laraval::init() }} 23 | 24 | 33 | ``` 34 | 35 | ### Using the rules from your backend 36 | When you pass rules into your view, you can `json_encode` them and assign it on the form's `data-laravel` html attribute. 37 | You can still use rules on the input elements, it will add/override the rules. 38 | ```php 39 | $rules = [ 40 | 'title' => 'required|max:15|alpha_num', 41 | 'body' => 'required|max:255|alpha_dash', 42 | 'between_dates' => 'after:1/1/2000|before:1/1/2010|date' 43 | ]; 44 | return view('myform', [ 45 | 'rules' => $this-rules 46 | ]); 47 | ``` 48 | 49 | ```html 50 |
52 | 53 | 54 | 55 |
56 | ``` 57 | 58 | 59 | ### Using the Facade / Factory inside views 60 | 61 | The easiest and quickest way to create validation is with the Facade (Factory class) 62 | ```html 63 |
64 | 65 | 66 | 67 |
68 | {!! Laraval::init() !!} 69 | {!! Laraval::local('#demo-form', [], $rules) !!} 70 | ``` 71 | 72 | ###### Facade methods that can be used to create validation 73 | ```php 74 | # init: Returns a @endif 10 | -------------------------------------------------------------------------------- /resources/views/demo.blade.php: -------------------------------------------------------------------------------- 1 | {{ Laraval::init() }} 2 | {{ Laraval::init() }} 3 | -------------------------------------------------------------------------------- /resources/views/demo/ajax.blade.php: -------------------------------------------------------------------------------- 1 | @extends('laraval::demo.layout') 2 | 3 | @section('title') 4 | Ajax Demo :: 5 | @parent 6 | @stop 7 | 8 | @section('form-element') 9 |
14 | @stop 15 |
16 | 17 | @section('init-script') 18 | {!! Laraval::init() !!} 19 | @parent 20 | {!! 21 | Laraval::make('ajax')->create('form#demo-form-laraval', [ 22 | 'url' => URL::route('laraval::demo.ajax.validate') 23 | ]) 24 | !!} 25 | @stop 26 | 27 | @push('scripts') 28 | 38 | @stop 39 | 40 | 41 | @section('form-content') 42 | 43 |
44 |
45 | {!! Form::demoTitle('general') !!} 46 | {!! Form::demoInput('title') !!} 47 | {!! Form::demoInput('body') !!} 48 | 49 | {!! Form::demoTitle('dates') !!} 50 | {!! Form::demoInput('born', '', 'date') !!} 51 | {!! Form::demoInput('died', '', 'date') !!} 52 | {!! Form::demoInput('between_dates', '', 'date') !!} 53 | 54 | {{-- 55 | {!! Form::demoInput('json', $laraval->rule('json'), 'text', 'JSON') !!} 56 | {!! Form::demoInput('ip', $laraval->rule('ip')) !!} 57 | 58 | {!! Form::demoTitle('numbers & integers') !!} 59 | {!! Form::demoInput('integer', 'integer', 'number') !!} 60 | {!! Form::demoInput('digits', 'digits:5', 'number') !!} 61 | {!! Form::demoInput('digits_between', 'digits_between:3,5', 'number') !!} 62 | {!! Form::demoInput('age', $laraval->rule('age'), 'number') !!} 63 | 64 | 65 | {!! Form::demoTitle('dates') !!} 66 | {!! Form::demoInput('born', $laraval->rule('born'), 'date') !!} 67 | {!! Form::demoInput('died', $laraval->rule('died'), 'date') !!} 68 | {!! Form::demoInput('between_dates', $laraval->rule('between_dates'), 'date') !!} 69 | --}} 70 | 71 |
72 |
73 |
74 |
75 |
76 | 77 | 78 | @stop 79 | -------------------------------------------------------------------------------- /resources/views/demo/form-builder.blade.php: -------------------------------------------------------------------------------- 1 | @extends('laraval::demo.layout') 2 | 3 | @section('title') 4 | Local Demo :: 5 | @parent 6 | @stop 7 | 8 | @section('form-element') 9 | {!! 10 | Form::open([ 11 | 'route' => 'laraval::demo.local.store', 12 | 'id' => 'demo-form-laraval', 13 | 'class' => 'form-horizontal', 14 | 'laraval' => $laraval 15 | ]) 16 | !!} 17 | 18 | @section('form-content') 19 | 20 |
21 |
22 | {!! Form::demoTitle('general') !!} 23 | {!! Form::demoInput('title') !!} 24 | {!! Form::demoInput('body') !!} 25 | {!! Form::demoInput('json', '', 'text', 'JSON') !!} 26 | {!! Form::demoInput('ip', $laraval->rule('ip')) !!} 27 | 28 | 29 | {!! Form::demoTitle('dates') !!} 30 | {!! Form::demoInput('born', '', 'date') !!} 31 | {!! Form::demoInput('died', '', 'date') !!} 32 | {!! Form::demoInput('between_dates', '', 'date') !!} 33 | 34 | 35 | {!! Form::demoTitle('numbers & integers') !!} 36 | {!! Form::demoInput('age', $laraval->rule('age'), 'number') !!} 37 | {!! Form::demoInput('integer', 'integer', 'number') !!} 38 | {!! Form::demoInput('digits', 'digits:5', 'number') !!} 39 | {!! Form::demoInput('digits_between', 'digits_between:3,5', 'number') !!} 40 | 41 | 42 | 43 | {!! Form::demoTitle('required variations') !!} 44 | {!! Form::demoInput('required_if', 'required_if:title,hello', 'text', 'if') !!} 45 | {!! Form::demoInput('required_with', 'required_with:title,body', 'text', 'with') !!} 46 | {!! Form::demoInput('required_with_all', 'required_with_all:title,body', 'text', 'with all') !!} 47 | {!! Form::demoInput('required_with_all2', 'required_with_all:title,body,unexisting', 'text', 'with all') !!} 48 | {!! Form::demoInput('required_without', 'required_without:title,body', 'text', 'with') !!} 49 | {!! Form::demoInput('required_without_all', 'required_without_all:title,body', 'text', 'with') !!} 50 | 51 | {!! Form::demoTitle('special') !!} 52 |
53 | 54 | 55 | 56 |
57 | {!! Form::demoTitle('Comparing') !!} 58 | {!! Form::demoInput('compare_same', 'same:title', 'text', 'Same') !!} 59 | {!! Form::demoInput('compare_different', 'different:title', 'text', 'Different') !!} 60 | {!! Form::demoInput('compare_in', 'in:foo,boo,da', 'text', 'in') !!} 61 | {!! Form::demoInput('compare_not_int', 'not_in:foo,boo,da', 'text', 'Not in') !!} 62 | 63 | {!! Form::demoTitle('size') !!} 64 | {!! Form::demoInput('size_string', 'size:5', 'text', 'String') !!} 65 | {!! Form::demoInput('size_number', 'size:5', 'number', 'Number') !!} 66 | {!! Form::demoInput('size_file', 'size:5', 'file', 'File') !!} 67 | 68 | {!! Form::demoTitle('min') !!} 69 | {!! Form::demoInput('min_string', 'min:5', 'text', 'String') !!} 70 | {!! Form::demoInput('min_number', 'min:5', 'number', 'Number') !!} 71 | {!! Form::demoInput('min_file', 'min:5', 'file', 'File') !!} 72 | 73 | {!! Form::demoTitle('max') !!} 74 | {!! Form::demoInput('max_string', 'max:5', 'text', 'String') !!} 75 | {!! Form::demoInput('max_number', 'max:5', 'number', 'Number') !!} 76 | {!! Form::demoInput('max_file', 'max:5', 'file', 'File') !!} 77 | 78 | {!! Form::demoTitle('') !!} 79 | 80 |
81 | 82 |
83 | 84 | 85 |
86 | 87 | 88 |
89 |
90 | 91 | 92 |
93 |
94 | @ 95 | 96 |
97 | 98 | (success) 99 |
100 |
101 | 102 |
103 | 104 | 105 |
106 |
107 | # 108 | 109 |
110 | 111 | (success) 112 |
113 |
114 | 115 | 116 |
117 | 118 | 119 |
120 |
121 | 125 |
126 |
127 | 131 |
132 |
133 |
134 |
135 | 136 | 137 |
138 | 139 |
140 |
141 | 142 | 143 | @stop 144 | 145 | @section('init-script') 146 | {!! $laraval->init() !!} 147 | @parent 148 | 153 | @stop 154 | -------------------------------------------------------------------------------- /resources/views/demo/input.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 |
6 | 0) 8 | data-laraval="{{ $rules }}" 9 | @endif 10 | > 11 | @if($type === 'date' || $type === 'file') 12 | {{$rules}} 13 | @endif 14 |
15 |
16 | -------------------------------------------------------------------------------- /resources/views/demo/layout.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @section('title') 7 | Laraval - Laravel jQuery Validation 8 | @show 9 | 10 | 11 | 12 | 13 | 14 | 15 | @stack('styles') 16 | 17 | 18 | 19 | 20 | @section('navbar') 21 | 51 | @show 52 |
53 |
54 | @section('errors') 55 | @if (count($errors) > 0) 56 | $errors->toArray(), 59 | 'toJson' => $errors->toJson(), 60 | 'all' => $errors->all(), 61 | 'jsonSerialize' => $errors->jsonSerialize() 62 | ]); 63 | ?> 64 | 65 |
66 |
    67 | @foreach ($errors->all() as $error) 68 |
  • {{ $error }}
  • 69 | @endforeach 70 |
71 |
72 | @endif 73 | @show 74 |
75 | 76 | @section('content') 77 |
78 |
79 | @section('form-element') 80 |
86 | @show 87 | {!! csrf_field() !!} 88 | @section('form-content') 89 | @show 90 | @section('form-actions') 91 |
92 | @section('form-action-buttons') 93 |
94 | 95 |
96 |
97 | 98 | 99 |
100 |
101 | 102 | 103 | 104 |
105 | @show 106 |
107 | @show 108 |
109 |
110 |
111 |
112 |
113 | @show 114 |
115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | @section('init-script') 130 | 155 | @show 156 | @section('demo-init-script') 157 | 160 | @show 161 | 162 | @stack('scripts') 163 | 164 | 165 | 166 | 167 | -------------------------------------------------------------------------------- /resources/views/demo/local.blade.php: -------------------------------------------------------------------------------- 1 | @extends('laraval::demo.layout') 2 | 3 | @section('title') 4 | Local Demo :: 5 | @parent 6 | @stop 7 | 8 | @section('form-element') 9 |
14 | @stop 15 |
16 | 17 | @section('init-script') 18 | {!! Laraval::init() !!} 19 | @parent 20 | {!! Laraval::create('local', 'form#demo-form-laraval', $rules, [/* options */]) !!} 21 | @stop 22 | 23 | @section('form-content') 24 | 25 |
26 |
27 | {!! Form::demoTitle('general') !!} 28 | {!! Form::demoInput('title') !!} 29 | {!! Form::demoInput('body') !!} 30 | {!! Form::demoInput('json', '', 'text', 'JSON') !!} 31 | {!! Form::demoInput('ip', '') !!} 32 | 33 | 34 | {!! Form::demoTitle('dates') !!} 35 | {!! Form::demoInput('born', '', 'date') !!} 36 | {!! Form::demoInput('died', '', 'date') !!} 37 | {!! Form::demoInput('between_dates', '', 'date') !!} 38 | 39 | 40 | {!! Form::demoTitle('numbers & integers') !!} 41 | {!! Form::demoInput('age', '', 'number') !!} 42 | {!! Form::demoInput('integer', 'integer', 'number') !!} 43 | {!! Form::demoInput('digits', 'digits:5', 'number') !!} 44 | {!! Form::demoInput('digits_between', 'digits_between:3,5', 'number') !!} 45 | 46 | 47 | 48 | {!! Form::demoTitle('required variations') !!} 49 | {!! Form::demoInput('required_if', 'required_if:title,hello', 'text', 'if') !!} 50 | {!! Form::demoInput('required_with', 'required_with:title,body', 'text', 'with') !!} 51 | {!! Form::demoInput('required_with_all', 'required_with_all:title,body', 'text', 'with all') !!} 52 | {!! Form::demoInput('required_with_all2', 'required_with_all:title,body,unexisting', 'text', 'with all') !!} 53 | {!! Form::demoInput('required_without', 'required_without:title,body', 'text', 'with') !!} 54 | {!! Form::demoInput('required_without_all', 'required_without_all:title,body', 'text', 'with') !!} 55 | 56 | {!! Form::demoTitle('special') !!} 57 |
58 | 59 | 60 |
61 | {!! Form::demoTitle('Comparing') !!} 62 | {!! Form::demoInput('compare_same', 'same:title', 'text', 'Same') !!} 63 | {!! Form::demoInput('compare_different', 'different:title', 'text', 'Different') !!} 64 | {!! Form::demoInput('compare_in', 'in:foo,boo,da', 'text', 'in') !!} 65 | {!! Form::demoInput('compare_not_int', 'not_in:foo,boo,da', 'text', 'Not in') !!} 66 | 67 | {!! Form::demoTitle('size') !!} 68 | {!! Form::demoInput('size_string', 'size:5', 'text', 'String') !!} 69 | {!! Form::demoInput('size_number', 'size:5', 'number', 'Number') !!} 70 | {!! Form::demoInput('size_file', 'size:5', 'file', 'File') !!} 71 | 72 | {!! Form::demoTitle('min') !!} 73 | {!! Form::demoInput('min_string', 'min:5', 'text', 'String') !!} 74 | {!! Form::demoInput('min_number', 'min:5', 'number', 'Number') !!} 75 | {!! Form::demoInput('min_file', 'min:5', 'file', 'File') !!} 76 | 77 | {!! Form::demoTitle('max') !!} 78 | {!! Form::demoInput('max_string', 'max:5', 'text', 'String') !!} 79 | {!! Form::demoInput('max_number', 'max:5', 'number', 'Number') !!} 80 | {!! Form::demoInput('max_file', 'max:5', 'file', 'File') !!} 81 | 82 | {!! Form::demoTitle('') !!} 83 | 84 |
85 | 86 |
87 | 88 | 89 |
90 | 91 | 92 |
93 |
94 | 95 | 96 |
97 |
98 | @ 99 | 100 |
101 | 102 | (success) 103 |
104 |
105 | 106 |
107 | 108 | 109 |
110 |
111 | # 112 | 113 |
114 | 115 | (success) 116 |
117 |
118 | 119 | 120 |
121 | 122 | 123 |
124 |
125 | 129 |
130 |
131 | 135 |
136 |
137 |
138 |
139 | 140 | 141 |
142 | 143 |
144 |
145 | 146 | 147 | @stop 148 | -------------------------------------------------------------------------------- /resources/views/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery accordion form with validation 6 | 7 | 8 | 9 | 10 | 76 | 77 | 78 | 79 |
80 |
81 |

82 | Help meBuy and Sell a House

83 |

This form is quick & easy to complete - in only 3 steps!

84 |
85 | 86 | 87 |
    88 |
  • 89 | 90 |
    91 |
    92 | Step 1 of 3 93 |
    *Required Field
    94 |

    Tell us about the property you're buying

    95 |   No: 97 |      Yes: 98 | 99 |
    100 | 101 | 109 |
    110 | 111 | 127 |
    128 | 129 | 183 |
    184 | 185 | 195 |
    196 |
    197 | 198 |
    199 |
    200 |
    201 |
  • 202 |
  • 203 | 204 | 205 |
    206 |
    207 | Step 2 of 3 208 |
    *Required Field
    209 |

    Tell us about the property you're selling

    210 | 211 | 219 |
    220 | 221 | 231 |
    232 | 233 | 234 |
    235 | 236 | 237 |
    238 | 239 | 240 |
    241 | 242 | 296 |
    297 | 298 | 299 |
    300 | 301 | 317 |
    318 | 319 | 327 |
    328 | 329 | 339 |
    340 | 341 | 349 |
    350 | 351 | 352 |
    353 |
    354 | 355 | 356 |
    357 |
    358 |
    359 |
  • 360 |
  • 361 | 362 | 363 |
    364 |
    365 | Step 3 of 3 366 |
    *Required Field
    367 |

    Tell us about yourself

    368 | 369 | 370 |
    371 | 372 | 373 |
    374 | 375 | 376 |
    377 | 378 | 379 |
    380 | 381 | 382 |
    383 | 384 | 438 |
    439 | 440 | 441 |
    442 | 443 | 444 |
    445 | 446 | 447 |
    448 | 449 | 450 |
    451 | 452 | 453 |
    454 |
    455 |

    This is a sample form, no information is sent anywhere.

    456 |
    457 | 458 | 459 |
    460 |
    461 |
    462 |
  • 463 |
464 |
465 |
466 |
467 | 468 | 469 | -------------------------------------------------------------------------------- /resources/views/init.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /run: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | 4 | postcommit(){ 5 | local TAG_LAST="$(git describe --abbrev=0 --tags)" 6 | git push -u origin master 7 | git push -u origin ${TAG_LAST} 8 | npm publish 9 | } 10 | 11 | preupdate(){ 12 | grunt dist 13 | git add -A 14 | git commit -m "pre-tag build" 15 | 16 | git_current_branch(){ 17 | branch_name=$(git symbolic-ref -q HEAD) 18 | branch_name=${branch_name##refs/heads/} 19 | branch_name=${branch_name:-HEAD} 20 | echo "${branch_name}" 21 | } 22 | 23 | git push -u origin "$(git_current_branch)" 24 | } 25 | 26 | ghpages(){ 27 | 28 | rm -rf gh-pages 29 | 30 | docgen generate 31 | grunt copy:docdemo 32 | 33 | cd gh-pages 34 | git init 35 | git checkout -b gh-pages 36 | git remote add origin https://github.com/robinradic/laraval 37 | git add -A 38 | git commit -m "new" 39 | git push -u origin gh-pages --force 40 | 41 | } 42 | 43 | $* 44 | -------------------------------------------------------------------------------- /src/Contracts/Factory.php: -------------------------------------------------------------------------------- 1 | create($selector, $options) 58 | * 59 | * @param $strategy 60 | * @param $selector 61 | * @param array $rules 62 | * @param array $options 63 | * @return string 64 | */ 65 | public function create($strategy, $selector, array $rules = [ ], array $options = [ ]); 66 | 67 | /** 68 | * Checks if a strategy exists 69 | * 70 | * @param $name 71 | * @return bool 72 | */ 73 | public function hasStrategy($name); 74 | 75 | /** 76 | * get initView value 77 | * 78 | * @return string 79 | */ 80 | public function getInitView(); 81 | 82 | /** 83 | * Set the initView value 84 | * 85 | * @param string $initView 86 | * @return Factory 87 | */ 88 | public function setInitView($initView); 89 | } 90 | -------------------------------------------------------------------------------- /src/Facades/Laraval.php: -------------------------------------------------------------------------------- 1 | create($selector, $options, $data) 23 | * @method string ajax(string $selector, array $opts = [], array $rules = [], array $data = []) - shorthand for make($strategy, $rules)->create($selector, $options, $data) 24 | */ 25 | class Factory implements LaravalContract 26 | { 27 | /** 28 | * @var \Illuminate\Contracts\Container\Container 29 | */ 30 | protected $container; 31 | 32 | /** 33 | * @var \Sebwite\Support\Filesystem 34 | */ 35 | protected $files; 36 | 37 | /** 38 | * @var array 39 | */ 40 | protected $laravalConfig; 41 | 42 | /** 43 | * @var \Illuminate\Contracts\Routing\UrlGenerator 44 | */ 45 | protected $url; 46 | 47 | /** 48 | * @var mixed 49 | */ 50 | protected $strategies; 51 | 52 | protected $initView = 'laraval::init'; 53 | 54 | /** Instantiates the class 55 | * 56 | * @param \Illuminate\Contracts\Container\Container $container 57 | * @param \Sebwite\Support\Filesystem $files 58 | * @param \Illuminate\Contracts\Config\Repository $configRepository 59 | * @param \Illuminate\Contracts\Routing\UrlGenerator $url 60 | */ 61 | public function __construct(Container $container, Filesystem $files, Repository $configRepository, UrlGenerator $url) 62 | { 63 | $this->container = $container; 64 | $this->files = $files; 65 | $this->laravalConfig = $configRepository->get('laraval'); 66 | $this->url = $url; 67 | 68 | $this->strategies = $this->config('strategies'); 69 | } 70 | 71 | /** 72 | * config 73 | * 74 | * @param null $key 75 | * @param null $default 76 | * @return mixed 77 | */ 78 | public function config($key = null, $default = null) 79 | { 80 | return $key ? array_get($this->laravalConfig, $key, $default) : $this->laravalConfig; 81 | } 82 | 83 | /** 84 | * Create new validation using the given strategy 85 | * 86 | * @param $strategy 87 | * @param array $rules 88 | * @return \Radic\Laraval\Strategies\ValidationStrategy 89 | */ 90 | public function make($strategy, array $rules = [ ]) 91 | { 92 | return $this->container->make($this->strategies[ $strategy ], [ 93 | 'factory' => $this, 94 | 'container' => $this->container, 95 | 'rules' => $rules 96 | ]); 97 | } 98 | 99 | /** 100 | * Returns javascript code that will extend the default settings on $.validator.defaults 101 | * 102 | * @param array $defaults 103 | * @return string 104 | */ 105 | public function init($defaults = [ ]) 106 | { 107 | $defaults = array_replace_recursive( 108 | $this->config('client_defaults'), 109 | $defaults 110 | ); 111 | 112 | return view($this->initView, compact('defaults'))->render(); 113 | } 114 | 115 | /** 116 | * Shorthand for make($strategy, $rules)->create($selector, $options) 117 | * 118 | * @param $strategy 119 | * @param $selector 120 | * @param array $rules 121 | * @param array $options 122 | * @return string 123 | */ 124 | public function create($strategy, $selector, array $rules = [ ], array $options = [ ]) 125 | { 126 | return $this->make($strategy, $rules)->create($selector, $options); 127 | } 128 | 129 | /** 130 | * Adds a new strategy 131 | * 132 | * @param $name 133 | * @param $strategyClass 134 | */ 135 | public function extend($name, $strategyClass) 136 | { 137 | $this->strategies[ $name ] = $strategyClass; 138 | } 139 | 140 | /** 141 | * Checks if a strategy exists 142 | * 143 | * @param $name 144 | * @return bool 145 | */ 146 | public function hasStrategy($name) 147 | { 148 | return isset($this->strategies[ $name ]); 149 | } 150 | 151 | 152 | 153 | /** 154 | * Dynamically call the default driver instance. 155 | * 156 | * @param string $method 157 | * @param array $parameters 158 | * @return mixed 159 | */ 160 | public function __call($method, $parameters) 161 | { 162 | //$fa->local(0=$selector, 1=$opts = [], 2=$rules = [], 3=$data = []); 163 | if ($this->hasStrategy($method)) { 164 | $selector = $parameters[0]; 165 | $options = isset($parameters[1]) ? $parameters[1] : []; 166 | $rules = isset($parameters[2]) ? $parameters[1] : []; 167 | $data = isset($parameters[3]) ? $parameters[1] : []; 168 | return $this->make($method, $rules)->create($selector, $options, $data); 169 | } else { 170 | throw new \BadMethodCallException("Method [{$method}] does not exist. Neither does a validation strategy with this name"); 171 | } 172 | } 173 | 174 | /** 175 | * get initView value 176 | * 177 | * @return string 178 | */ 179 | public function getInitView() 180 | { 181 | return $this->initView; 182 | } 183 | 184 | /** 185 | * Set the initView value 186 | * 187 | * @param string $initView 188 | * @return Factory 189 | */ 190 | public function setInitView($initView) 191 | { 192 | $this->initView = $initView; 193 | 194 | return $this; 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/Http/Controllers/Demo/AjaxDemoController.php: -------------------------------------------------------------------------------- 1 | 'ajax', 25 | 'rules' => $this->rules 26 | ]); 27 | } 28 | 29 | public function ajaxValidate(Request $request) 30 | { 31 | return $this->laraval->make('ajax', $this->rules)->validate($request); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Http/Controllers/Demo/DemoController.php: -------------------------------------------------------------------------------- 1 | 'required|max:15|alpha_num', 31 | 'body' => 'required|max:255|alpha_dash', 32 | 'json' => 'json', 33 | 'ip' => 'ip', 34 | 'age' => 'required|between:18,30|numeric', 35 | 'born' => 'required|date|after:1/1/2000', 36 | 'died' => 'required|date|after:born', 37 | 'between_dates' => 'after:1/1/2000|before:1/1/2010|date', 38 | 'email' => 'required|email', 39 | 'url' => 'required|url', 40 | 'is_admin' => 'boolean', 41 | 'active' => 'boolean' 42 | ]; 43 | 44 | /** 45 | * @var \Radic\Laraval\Factory 46 | */ 47 | protected $laraval; 48 | 49 | public function __construct(Factory $factory) 50 | { 51 | require_once(realpath(__DIR__ . '/macros.php')); 52 | $this->laraval = $factory; 53 | 54 | } 55 | 56 | public function store(Request $request) 57 | { 58 | $this->validate($request, $this->rules); 59 | 60 | return \Response::json($this->errorBag()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Http/Controllers/Demo/FormBuilderDemoController.php: -------------------------------------------------------------------------------- 1 | 'builder', 34 | 'laraval' => $this->laraval 35 | ]); 36 | } 37 | 38 | public function ajaxValidate(Request $request) 39 | { 40 | return $this->laraval->validate($request, $this->rules); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Http/Controllers/Demo/LocalDemoController.php: -------------------------------------------------------------------------------- 1 | 'local', 23 | 'rules' => $this->rules 24 | ]); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Http/Controllers/Demo/macros.php: -------------------------------------------------------------------------------- 1 | render(); 9 | }); 10 | Form::macro('demoTitle', function ($title) { 11 | 12 | return '

' . ucfirst($title) . '

'; 13 | }); 14 | } 15 | -------------------------------------------------------------------------------- /src/Http/routes.php: -------------------------------------------------------------------------------- 1 | route('laraval::demo.local.show'); 5 | }); 6 | 7 | Route::group([ 'as' => 'local.', 'prefix' => 'local' ], function () { 8 | 9 | Route::get('/', [ 'as' => 'show', 'uses' => 'LocalDemoController@show' ]); 10 | Route::post('store', [ 'as' => 'store', 'uses' => 'LocalDemoController@store' ]); 11 | }); 12 | 13 | Route::group([ 'as' => 'ajax.', 'prefix' => 'ajax' ], function () { 14 | 15 | Route::get('/', [ 'as' => 'show', 'uses' => 'AjaxDemoController@show' ]); 16 | Route::post('/', [ 'as' => 'store', 'uses' => 'AjaxDemoController@store' ]); 17 | Route::post('validate', [ 'as' => 'validate', 'uses' => 'AjaxDemoController@ajaxValidate' ]); 18 | }); 19 | 20 | Route::group([ 'as' => 'builder.', 'prefix' => 'builder' ], function () { 21 | 22 | Route::get('/', [ 'as' => 'show', 'uses' => 'FormBuilderDemoController@show' ]); 23 | Route::post('/', [ 'as' => 'store', 'uses' => 'FormBuilderDemoController@store' ]); 24 | Route::post('validate', [ 'as' => 'validate', 'uses' => 'FormBuilderDemoController@ajaxValidate' ]); 25 | }); 26 | -------------------------------------------------------------------------------- /src/LaravalServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'laraval' ]; 22 | 23 | protected $assetDirs = [ 'assets' => 'laraval' ]; 24 | 25 | protected $providers = [ 26 | Providers\RouteServiceProvider::class 27 | ]; 28 | 29 | protected $provides = [ 'laraval' ]; 30 | 31 | protected $singletons = [ 32 | 'laraval' => Factory::class 33 | ]; 34 | 35 | protected $aliases = [ 36 | 'laraval' => Contracts\Factory::class 37 | ]; 38 | 39 | 40 | /** 41 | * {@inheritdoc} 42 | */ 43 | public function boot() 44 | { 45 | $app = parent::boot(); 46 | } 47 | 48 | /** 49 | * {@inheritdoc} 50 | */ 51 | public function register() 52 | { 53 | $app = parent::register(); 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | group([ 58 | 'as' => 'laraval::demo.', 59 | 'prefix' => 'laraval', 60 | 'namespace' => $this->namespace 61 | ], function (Router $router) { 62 | require(realpath(__DIR__ . '/../Http/routes.php')); 63 | }); 64 | } 65 | 66 | 67 | 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Strategies/AjaxValidationStrategy.php: -------------------------------------------------------------------------------- 1 | validationFactory = $validationFactory; 54 | $this->responseFactory = $responseFactory; 55 | } 56 | 57 | /** 58 | * @inheritdoc 59 | */ 60 | public function create($selector = 'form', array $options = [ ], array $data = [ ]) 61 | { 62 | $options = array_replace_recursive([ 63 | //'messages' => static::flatten($this->messages) 64 | ], $options); 65 | 66 | $data = array_replace_recursive([ 67 | 'rules' => null 68 | ], $data); 69 | 70 | return parent::create($selector, $options, $data); 71 | } 72 | 73 | /** 74 | * Validates a AJAX validation request and returns a JsonResponse 75 | * 76 | * @param \Illuminate\Http\Request $request 77 | * @param array $rules 78 | * @param array $messages 79 | * @return \Illuminate\Http\JsonResponse 80 | */ 81 | public function validate(Request $request, array $rules = [ ], array $messages = [ ]) 82 | { 83 | $rules = $this->getRules()->merge($rules)->toArray(); 84 | 85 | if ($singleField = $request->has($this->singleFieldReferenceKey)) { 86 | $fields = [ $request->get($this->singleFieldReferenceKey) ]; 87 | } else { 88 | $fields = Arr::keys($this->getRules()->toArray()); 89 | } 90 | 91 | $data = $request->only($fields); 92 | $rules = Arr::only($rules, $fields); 93 | 94 | $validator = $this->validationFactory->make($data, $rules, $messages); 95 | 96 | if ($validator->fails()) { 97 | $messages = $validator->getMessageBag(); 98 | 99 | if ($singleField) { 100 | $fieldName = $request->get($this->singleFieldReferenceKey); 101 | 102 | return $this->jsonResponse([ $fieldName => $messages->first($fieldName) ]); 103 | } else { 104 | $response = [ ]; 105 | foreach ($messages->keys() as $key) { 106 | $response[ $key ] = $messages->first($key); 107 | }; 108 | 109 | return $this->jsonResponse($response); 110 | } 111 | } else { 112 | return $this->jsonResponse('true'); 113 | } 114 | } 115 | 116 | protected function jsonResponse($data = [ ], $status = 200) 117 | { 118 | return $this->responseFactory->json($data, $status); 119 | } 120 | 121 | /** 122 | * get singleFieldReferenceKey value 123 | * 124 | * @return string 125 | */ 126 | public function getSingleFieldReferenceKey() 127 | { 128 | return $this->singleFieldReferenceKey; 129 | } 130 | 131 | /** 132 | * Set the singleFieldReferenceKey value 133 | * 134 | * @param string $singleFieldReferenceKey 135 | * @return AjaxValidationStrategy 136 | */ 137 | public function setSingleFieldReferenceKey($singleFieldReferenceKey) 138 | { 139 | $this->singleFieldReferenceKey = $singleFieldReferenceKey; 140 | 141 | return $this; 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /src/Strategies/LocalValidationStrategy.php: -------------------------------------------------------------------------------- 1 | loadMessages(); 41 | } 42 | 43 | /** 44 | * @inheritdoc 45 | */ 46 | public function create($selector = 'form', array $options = [ ], array $data = [ ]) 47 | { 48 | $options = array_replace_recursive([ 49 | 'messages' => static::flatten($this->messages) 50 | ], $options); 51 | 52 | $data = array_replace_recursive([ 53 | //'rules' => new Collection() 54 | ], $data); 55 | 56 | return parent::create($selector, $options, $data); 57 | } 58 | 59 | 60 | /** 61 | * loadMessages 62 | * 63 | * @param array $extraLocales 64 | * @param string $langsPath 65 | * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException 66 | */ 67 | public function loadMessages(array $extraLocales = [ ], $langsPath = 'resources/lang') 68 | { 69 | $this->messages = [ ]; 70 | $langs = array_merge([ config('app.locale') ], $extraLocales, [ 'en' ]); 71 | foreach ($langs as $lang) { 72 | $path = Path::join($langsPath, $lang, 'validation.php'); 73 | $path = base_path($path); 74 | if ($this->getFiles()->exists($path)) { 75 | $this->messages = array_replace_recursive($this->messages, $this->getFiles()->getRequire($path)); 76 | } 77 | } 78 | } 79 | 80 | /** 81 | * flattens an array 82 | * 83 | * @param $array 84 | * @param string $prepend 85 | * @return array 86 | */ 87 | protected static function flatten($array, $prepend = '') 88 | { 89 | $results = [ ]; 90 | 91 | 92 | foreach ($array as $key => $value) { 93 | if (is_array($value)) { 94 | $results = array_merge($results, static::flatten($value, $prepend . $key . '_')); 95 | } else { 96 | $results[ $prepend . $key ] = $value; 97 | } 98 | } 99 | 100 | return $results; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /src/Strategies/ValidationStrategy.php: -------------------------------------------------------------------------------- 1 | tag 52 | * 53 | * @var bool 54 | */ 55 | protected $embed; 56 | 57 | /** 58 | * If set and using $this->embed, the $embedAttributes will be appended inside the script tag like