Download the PHP package ashkanrimer/hashids without Composer

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

hashids

Build Status Monthly Downloads Latest Version

Hashids is a small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database numeric ids to users: https://hashids.org/php

This is a wrapper around the original hashids/hashids package. For basic documentation refer to the original one.

https://github.com/vinkla/hashids

The above badges are for the original package.

Installation

Require this package, with Composer, in the root directory of your project.

Then you can enjoy the full features of the original package. Refer to their documentation for more details.

Herein, I just describe what has been added to it.

Advantages Over the Original Package

  1. It's configured for the most-appropriate usages, with alphabets and lengths already set out of the box.
  2. The encoder doesn't return an array for a single id. You don't have to worry about array/string conversions.
  3. Bypasser is a great tool if you face trouble.
  4. The model trait can be used on eloquent models and easily provide hashid tools.
  5. You can still enjoy all the benefits provided by the original package, without any overheads.

Basic Usage

The first thing you need to do is to define your salt in your .env file.

Hashids must not be used as a means of security, but it is a good practice to redefine the salt per app.

Then, you are ready to convert ids and hashids to each other, through easy helper functions.

No matter what the input is, the hashid function will always switch.

Use the below methods, if you want to be sure the returned data is of the desired type.

All the above methods receive arrays as well.

Model Helpers

As the most important usage of this package is to hide table ids, we have introduced a special trait to be used in your model.

Then, the hashid accessor is added to your model.

Moreover, a query scope is added to easily filter records by their hashids, instead of ids:

It's ok if you include real ids in the array. I.e. You don't have to ensure everything received is in the form of hashids. A mix of real ids and hashids work too.

:warning: Never save a hashid in your database. The key can be changed and you will lose your data.

Easy Bypass

Debugging the app when the hashids are engaged can be a real headache, as you have to constantly convert things in the tinker and see what is what.

To deal with this problem, you can bypass the mechanism in your .env file.

This will bypass real encryption and just convert ids to an equivalent string to make you easily read the responses and follow the probable bugs.

:warning: Be sure to do this in the development mode only.

Custom Salts

You can define custom salts and freely use them in your app.

First, publish the config.

The fully-commented config file will be published and you can define as many salts as you may need.

The above helper functions can handle your custom salts by receiving a second argument.

Advanced Usage

Easy switching between ids and hashids is not what you may always want. While the above helper functions are designed to try their best to find the most appropriate values, you may want to have errors if the user submits id instead of hashid.

The below methods will not automatically convert things.

Moreover, you can have more control over the minimum length and the alphabets, using the below methods:

Note that passing null as the alphabet will instruct the method to use the custom alphabet, which consists of English letters with no digits involved.

License

To respect the efforts made by the original maintainer, I have not touched any of the licenses.

Ivan Akimov


All versions of hashids with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-mbstring Version *
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 ashkanrimer/hashids contains the following files

Loading the files please wait ....