Download the PHP package ditscheri/laravel-check-constraints without Composer

On this page you can find all versions of the php package ditscheri/laravel-check-constraints. 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-check-constraints

Add check constraints to your Laravel schema

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This packages allows you to add native check constraints to your database tables.

You can read more about check constraints in the official documentations of MySQL, PostrgeSQL, SQLite and SQL Server.

Currently, this package does not add check constraints to the SQLite driver, but you should be fine if you only use SQLite for running tests (see below).

Installation

You can install the package via composer:

Usage

That last statement will produce the following SQL:

Now your database will only allow inserts and updates for rows with a valid date range.

If you try to insert or update a row that violates the check, an \Illuminate\Database\QueryException will be thrown:

Another simple yet typical use case is with prices and discounts:

Of course you will still want to validate your data within the application code and detect such things before even reaching out to the database. But sometimes it is useful to have an additional layer of integrity checks right in your database itself.

Especially when you read data back from your database, your code may now safely assume that all the defined checks are guaranteed.

You can also add checks to existing tables:

Use the second parameter for an optional custom constraint name:

You can drop check constraints by their name:

A note about SQLite

While SQLite does support check constraints within create table statements, there are a number of limitions:

Since this package only relies on macros, it currently does not support the SQLite driver at all.

Instead, you can use the config check-constraints.sqlite.throw to define wether to throw a RuntimeException or to fail silently when using SQLite.

If you only use SQLite in your tests, you might be fine with setting the option to false. This gives you all the benefits of check constraints for your production environment, while your tests can still run using SQLite, where the calls to $table->check() will just be skipped.

Configuration

You can publish the config file with:

This is the contents of the published config file:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-check-constraints with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
spatie/laravel-package-tools Version ^1.9.2
illuminate/contracts Version ^8.0|^9.0|^10.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 ditscheri/laravel-check-constraints contains the following files

Loading the files please wait ....