PHP code example of indy2kro / laravel-validate-models

1. Go to this page and download the library: Download indy2kro/laravel-validate-models 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/ */

    

indy2kro / laravel-validate-models example snippets


php artisan vendor:publish --tag=validate-models-config

return [
    'models_paths' => [base_path('app/Models')],
    'models_namespaces' => ['App\\Models'],
    'connection' => null,

    'checks' => [
        'columns'   => true,
        'casts'     => true,
        'fillable'  => true,
        'relations' => true,
        'annotations'=> true,
    ],

    'annotations' => [
        'columns_only' => true, // only check @property names that exist as columns
        'check_casts'  => true, // also compare annotation types vs model casts
        'check_nullability' => true, // enable/disable nullable enforcement
        'ignore'       => [     // names to ignore
        ],
        'aliases'      => [     // map short names used in @property tags to FQCNs 
        ],
    ],

    'ignore' => [
        'casts'     => [],
        'fillable'  => [],
        'columns'   => [],
        'relations' => [],
    ],

    'fail_on_warnings' => true,

    'type_map' => [
        '*' => [
            'integer'  => ['int','integer','bigint','smallint','tinyint'],
            'string'   => ['string','varchar','char','text','enum','set'],
            'boolean'  => ['bool','boolean','tinyint'],
            'float'    => ['float','double','decimal'],
            'decimal'  => ['decimal','numeric'],
            'datetime' => ['datetime','timestamp'],
            'json'     => ['json','jsonb','array'],
            'array'    => ['json','jsonb','array'],
        ],
    ],
];

php artisan validate:models