PHP code example of timacdonald / rule-builder
1. Go to this page and download the library: Download timacdonald/rule-builder 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/ */
timacdonald / rule-builder example snippets
$rules = [
'name' => Rule::255)
->get(),
'email' => Rule::nique('users')
->get(),
'password' => Rule::
Rule::activeUrl($max)
->alpha($min, $max)
->alphaDash($min, $max)
->alphaNum($min, $max)
->array($min, $max)
->email($max)
->file($max)
->image($max)
->integer($min, $max)
->json($max)
->numeric($min, $max)
->string($min, $max)
->url($max)
$rules = [
'age' => Rule::integer(21)->get(),
'dollars' => Rule::numeric(0, 999.99)->get(),
'email' => Rule::email(255)->get(),
];
$rules = [
'notifications' => Rule::add(new MyValidationRule)
->add(new MyOtherValidationRule)
->get(),
];
$rules = [
'due_date' => Rule::after(Carbon::now()->addYear())->get()
];
$rules = [
'username' => Rule::t(),
];
$rules = [
'email' => Rule::unique('users')->where(function ($query) {
$query->where('account_id', 1);
})->email(255)->get(),
];
$rules = [
'subscription_id' => Rule::foreignKey(Subscription::class)->get(),
];
$rules = [
'title' => Rule::unique(Post::class, 'title')->get(),
];
namespace App\Providers;
use TiMacDonald\Validation\Rule;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Validator::extend('foo_bar', function ($attribute, $value, $parameters, $validator) {
return $value === 'foo_bar';
});
Rule::extend(['foo_bar']);
}
$rules = [
'name' => Rule::string()->fooBar()->get(),
];
$rules = [
'name' => Rule::string()->fooBar('baz')->get(),
];
$rules = [
'email' => Rule::email()->raw('min:10|max:255')->get(),
];
$rules = [
'email' => (string) Rule::
Validator::extend('not_empty_html', function ($attribute, $value) {
return trim(strip_tags($value)) !== '';
});
Rule::extend(['not_empty_html']);
php
$rules = [
'profile' => Rule::urlWithScheme(['https', 'fb'])->get(),
];