PHP code example of laravel-ardent / laravalid

1. Go to this page and download the library: Download laravel-ardent/laravalid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

laravel-ardent / laravalid example snippets


    'providers' => [
        ...
        'LaravelArdent\Laravalid\LaravalidServiceProvider',
    ],
    
    'aliases' => [
        ...
        'HTML' => 'Illuminate\Support\Facades\HTML',
        'Form' => 'LaravelArdent\Laravalid\Facade',
    ],

$ ./artisan vendor:publish

 return [
    '
        'string' => 'This is too short',
        'number' => 'This is too low',
    ]
    //...
];

    $rules = ['name' => ' 'foo/bar', 'method' => 'put'], $rules);
    Form::text('name');
    Form::text('email');
    Form::text('birthdate');
    Form::close(); // don't forget to close form, it reset validation rules
    
    // in controller or route
    $rules = ['name' => 'lso use without giving form name Form::setValidation($rules) because there is just one.
    
    // in view
    Form::open(array('url' => 'foo/bar', 'method' => 'put', 'name' => 'firstForm'), $rules);
    // some form inputs
    Form::close();

    $rules = ['age' => 'numeric|max'];

    // you can bring in the rules from the model...
    Form::open(['url' => 'foo/bar', 'method' => 'put'], App\Models\User::$rules);
    // ...or use the model form to make things even cleaner: the rules will be imported from it!
    Form::model($user, ['url' => 'foo/bar', 'method' => 'put']);

class UserController extends Controller {
    
    public $createValidation = ['name' => 'tCreate()
    {
        Form::setValidation($this->createValidation);
        return View::make('user.create');
    }

    public function postCreate()
    {
        $inputs = Input::only($this->createColumns);
        $rules = $this->createValidation;

        $validator = Validator::make($inputs, $rules);

        if($validator->fails())
        {
            // actually withErrors is not really neccessary because we already show errors at client side for normal users
            return Redirect::back()->withErrors($validator);
        }

        // try to create user

        return Redirect::back()->with('success', 'User is created successfully');
    }
}

Form::converter()->rule()->extend('someotherrule', function($parsedRule, $attribute, $type){
    // some code
    return ['data-rule-someotherrule' => 'blablabla'];
});
Form::converter()->message()->extend('someotherrule', function($parsedRule, $attribute, $type){
    // some code
    return ['data-message-someotherrule' => 'Some other message'];
});
Form::converter()->route()->extend('someotherrule', function($name, $parameters){
    // some code
    return ['valid' => false, 'messages' => 'Seriously dude, what kind of input is this?'];
});