Giter Site home page Giter Site logo

etopian / validator-factory Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yaroslawww/validator-factory

0.0 1.0 0.0 37 KB

Standalone library to use Illuminate\\Validation package outside the Laravel framework.

License: MIT License

PHP 100.00%

validator-factory's Introduction

ValidatorFactory

Standalone library to use the Illuminate\Validation package outside the Laravel framework.

Installation

From your terminal, run:

$ composer require etopian/validator-factory

Usage

You need to create a new instance of the ValidatorFactory class.

$factory = new etopian\ValidatorFactory();

$validator = $factory->make($data = [], $rules);

This will return an instance of Illuminate\Validation\Validator::class.

You can learn more about the Laravel Validator in the official documentation website.

Customizing error messages

You can specify a custom translation root directory

$validator->translationsRootPath(__DIR__ . '/../../src/')
    ->make($data = [], $rules = ['foo' => 'required'])

Inside that directory you will need to create the following structure:

- lang/
  - en/
    - validation.php

You can customize the structure above by specifying the following values when you create a new instance of the ValidatorFactory::class

$factory = new ValidatorFactory($namespace = 'lang', $lang = 'en', $group = 'validation');

If your plan is to use a custom rule object you would generally call the trans helper inside your messages() method when working inside of Laravel. However you will not have access to the trans helper outside of Laravel so you will need to use ValidatorFactory::trans($key) instead.

validator-factory's People

Contributors

etopian avatar jeffochoa avatar nunomaduro avatar albinodrought avatar svenluijten avatar yaroslawww avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.