Download the PHP package rossbearman/eloquent-calamari without Composer

On this page you can find all versions of the php package rossbearman/eloquent-calamari. 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 eloquent-calamari

Eloquent Calamari - Sqids for Laravel Models

Latest Stable Version Test Status Analysis Status MIT Licensed

Eloquent Calamari integrates the Sqids[^1] algorithm into Laravel and Eloquent, enabling you to seamlessly use obfuscated, unique IDs in place of your internal auto-incrementing IDs.

example.com/link/2fC37YMkO === Link::find(1)

example.com/video/TaRfL1RAK === Video::find(1)

Getting Started

Require this package with Composer.

composer require rossbearman/eloquent-calamari

Add the HasSqid and SqidBasedRouting traits to your models.

Create a route for your model.

example.com/customer/3irWXI2rFV now returns the Customer details.

Querying

Common query methods are also available.

Representation

By default the Sqid is not included in the model's toArray() or toJson() output and the ID is not hidden from these. You can use Eloquent's appends and hidden properties to achieve this.

Custom Routing

You can take advantage of SqidBasedRouting while still having a different default binding by overriding the model's getRouteKeyName() method.

Configuration

By default, Eloquent Calamari generates a random alphabet for each model, by shuffling the default alphabet with the Xoshiro256StarStar algorithm, seeded with a combination of the name of the model and the key set in the config.

This ensures that entities of different models with the same ID will have a unique Sqid, however it is fragile to the model name or app key being changed. If either of these are changed, Sqids will no longer resolve back to the same ID.

[!IMPORTANT] It is highly recommended that you explicitly set a pre-shuffled alphabet for each model using the sqids.alphabets config key, which will disable the shuffling behaviour for that model.

Setting alphabets

Start by publishing the sqids.php config file to your config directory.

Then generate a new alphabet for your model.

You can also generate alphabets for multiple models at once.

Follow the instructions provided by the command to add the new keys to your config/sqids.php and .env files.

Confirm alphabet is being used

To ensure that Eloquent Calamari is using the expected alphabet for a specific model, use the following command.

This will list all the models that have successfully been registered in the config and whether the class string can be resolved to a class in your application.

Setting minimum Sqid lengths

By default, all Sqids will be a minimum of 10 characters. You can adjust this for each model by assigning different values (to a minimum of 3) to the sqids.min_lengths config array.

The maximum length of a Sqid is dependent on the input ID and the alphabet used. A more varied alphabet (upper and lower case letters, numbers and symbols) will result in shorter Sqids.

Canonical Sqids

By design, multiple Sqids can resolve to the same number, however Eloquent Calamari will always return the same Sqid for a given number. Furthermore, this is the only Sqid that can be used to access an entity, and any other Sqid that would normally resolve to the same number will be rejected.

This check can be disabled on a per-model basis by adding an entry to the sqids.canonical_checks config array.

Development

PHPUnit tests:

PHPStan analysis:

Pint linting:

Security

Please email Ross Bearman [email protected] if you have discovered a vulnerability in this package.

License

MIT License (MIT). Please see LICENSE.md for more information.

[^1]: Sqids is the latest version of the Hashids algorithm, redesigned to accomodate custom blocklists and a better encoding scheme.


All versions of eloquent-calamari with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-mbstring Version *
illuminate/config Version ^10.0 | ^11.0
illuminate/contracts Version ^10.0 | ^11.0
illuminate/database Version ^10.0 | ^11.0
illuminate/support Version ^10.0 | ^11.0
sqids/sqids Version ^0.4.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 rossbearman/eloquent-calamari contains the following files

Loading the files please wait ....