Download the PHP package proai/laravel-data-integrity without Composer

On this page you can find all versions of the php package proai/laravel-data-integrity. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-data-integrity

Laravel Data Integrity

Scan your Eloquent models for data integrity violations and fix them automatically.

Concept

An audit case is a class that groups one or more integrity checks for a given model. Each check* method defines a single audit that examines every record in chunks and reports violations. Audit cases are discovered automatically from database/audits/, and violations can be fixed in place when passed --fix.

Installation

The package auto-registers itself via Laravel's package discovery. The db:audit command is available immediately after installation.

Since audits live in database/audits/ by default, you need to register the namespace in your application's composer.json so the classes can be autoloaded:

Then run composer dump-autoload.

Usage

Creating an audit case

Create a class anywhere under database/audits/ extending ProAI\DataIntegrity\AuditCase. It will be discovered automatically. Each public check* method defines one audit and returns an Audit.

Inline audits

Define checks as individual methods using the fluent builder:

The validate closure receives a single model instance and a $fail closure. Call $fail(string $reason) to report a violation. The model identifier (e.g. Order #42:) is automatically prepended to the reason in the output.

To support --fix, pass an optional fix closure as the second argument to $fail:

The fluent builder supports query(), chunkSize(), before(), and after():

Description from method name

When no description is passed to audit(), it is derived from the method name automatically:

Lifecycle hooks: before and after

Use before and after to run logic before and after each chunk is validated. The before hook is useful for preloading related data or setting up shared state, while after can be used for cleanup or post-processing:

Reusable checks with IntegrityCheck

For checks that are shared across multiple audits, create a class implementing IntegrityCheck:

Then reference it in your audit case with auditUsing():

Check classes can accept constructor arguments, making them reusable across different models and relationships. The example above shows how BelongsToExists can verify any belongsTo relationship — just pass the relation name.

For counter cache validation, a generic check class avoids duplicating the same logic:

Check classes can also define optional before($chunk), after($chunk), query(), and description() methods. Use before to batch-load data per chunk instead of querying per model:

Registering check aliases

You can register short aliases for check classes and reference them by name:

Configuration

All global settings are managed through the AuditManager class. Configure them in a service provider:

Individual audits can still override the chunk size per check via the chunkSize() method.

API

AuditManager

Member Description
static defaultChunkSize(int $chunkSize): void Set the default chunk size (default: 1000)
static discoverIn(string $path): void Override the audit discovery path
static register(string $name, string $checkClass): void Register a named check alias
static flush(): void Reset all settings to defaults

AuditCase (abstract base class)

Member Description
protected $model Eloquent model class to scan
public function check*(): Audit Define a single audit (discovered via reflection)
$this->audit(?string $description): Audit Start an inline audit with the fluent builder
$this->auditUsing(string $class, array $args = []) Delegate to an IntegrityCheck class

Audit (fluent builder)

Method Description
query(Closure $callback) function ($query) — add constraints / eager loads
chunkSize(int $size) Records per chunk (defaults to the global default set via AuditManager)
before(Closure $callback) function ($chunk) — runs before each chunk
after(Closure $callback) function ($chunk) — runs after each chunk
validate(Closure $callback) function ($model, $fail) — validate a single model

IntegrityCheck (interface)

Optionally add before(EloquentCollection $chunk): void, after(EloquentCollection $chunk): void, query(): Closure, and/or description(): string methods.

$fail closure

Argument Type Description
$reason string Violation message (model ID is auto-prepended in output)
$fix Closure\|null Optional fix closure, called when --fix is passed. No arguments.

License

MIT


All versions of laravel-data-integrity with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
illuminate/console Version ^12.0|^13.0
illuminate/database Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
symfony/finder Version ^7.0|^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package proai/laravel-data-integrity contains the following files

Loading the files please wait ...