PHP code example of weloveahmed / laravel-auto-validator

1. Go to this page and download the library: Download weloveahmed/laravel-auto-validator 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/ */

    

weloveahmed / laravel-auto-validator example snippets


return [
    'ignore_columns' => [
        'id',
        'created_at',
        'updated_at',
        'deleted_at',
    ],
    'cache' => [
        'enabled' => true,
        'store' => env('AUTO_VALIDATOR_CACHE_STORE', null),
        'ttl' => 3600,
        'prefix' => 'auto_validator:',
    ],
    'overrides_path' => app_path('AutoValidation'),
    'profiles' => [
        // 'person' => [
        //     'name' => ['

use Weloveahmed\AutoValidator\Facades\AutoValidator;

$rules = AutoValidator::for(Employee::class)
    ->store()
    ->rules();

$data = AutoValidator::for(Employee::class)
    ->store()
    ->validate(request()->all());

$rules = AutoValidator::for(Employee::class)
    ->update($employee->id)
    ->rules();

$data = AutoValidator::for(Employee::class)
    ->update($employee->id)
    ->validate(request()->all());

return [
    'email' => ['e', 'regex:/^(01)[0-9]{9}$/'],
];

'profiles' => [
    'api-mobile' => [
        'mobile' => ['

$rules = AutoValidator::for(Employee::class)
    ->profile('api-mobile')
    ->store()
    ->rules();

use Weloveahmed\AutoValidator\Contracts\TenantResolver;

class MyTenantResolver implements TenantResolver
{
    public function enabled(): bool { return true; }
    public function tenantId(): mixed { return tenant('id'); }
    public function tenantKeyName(): string { return 'tenant_id'; }
}

$this->app->bind(TenantResolver::class, MyTenantResolver::class);

AutoValidator::for(Employee::class)
    ->store()
    ->softDeletes()
    ->rules();

return [
    'grades' => ['nullable', 'array'],
    'grades.*.year' => [',
];

$results = AutoValidator::for(Employee::class)
    ->store()
    ->bulk()
    ->validateRows($rows);

$validatedRows = $results->validated();
$errors = $results->errors();
bash
php artisan vendor:publish --tag=auto-validator-config
bash
php artisan autovalidator:request Employee
php artisan autovalidator:override Employee
php artisan autovalidator:profile person