Download the PHP package antoninmasek/laravel-model-hashids without Composer

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

Easily use Hashids with Laravel models.

Packagist Version GitHub Actions Workflow Status Packagist Downloads

In some cases I really like to use Hashids instead of uuids as my model keys. For me Hashids are less awkward to read and the resulting URL looks a bit nicer in my opinion. This package is inspired by laravel-model-uuid by Michael Dyrynda and aims to make it a breeze to start using Hashids as your model keys.

Installation

You can install the package via composer:

You can publish the config file with:

This is the contents of the published config file:

This package uses antoninmasek/laravel-hashids in the background. And if you wish to configure some aspects of the underlying hash id generation, then please take a look at a readme of the package.

Usage

To use this package you'll be most interested in the following two traits: GeneratesHashId and BindsOnHashId.

Generating hash id

In order for your model to automatically get a hash id after it is created just use GeneratesHashId trait on your model:

Binding on hash id

To also bind your model to hash id you also need to use BindsOnHashId trait:

Configuration

If you need to execute some logic in order to determine salt/alphabet/minlength you have a few callbacks at your disposal:

Global

If you want to set these globally you may use the following callbacks. The callback is supplied with the model as a parameter.

Local

If you wish to have a specific logic just for a certain model you may define these methods on the desired model:

Precedence

This is the order in which the values are taken:

  1. Model specific logic
  2. Global logic
  3. Config values
  4. Hashids package

Regenerating hash id

If you wish to regenerate a hash id for a particular model with current configuration you may do so as follows:

Limitations

If your model key is auto-incrementing then, at least at the moment, there are 2 round-trips to the database. 1st to create the model and receive the ID and then 2nd to set the hash_id based on the ID.

Note: Updating eloquent event is not fired, when setting the hash_id. This is the default behaviour since version 0.6.0. It is still possible to change this via save_quietly config setting.

Testing

Changelog

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

Credits

Antonín Mašek

License

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

Special thanks


All versions of laravel-model-hashids with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
antoninmasek/laravel-hashids Version ^1.0.0
illuminate/contracts Version ^10.0 || ^11.0
spatie/laravel-package-tools Version ^1.14.1
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 antoninmasek/laravel-model-hashids contains the following files

Loading the files please wait ....