Download the PHP package adamhopkinson/laravel-model-hash without Composer

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

laravel-model-hash

Automatically create short hashes for your Laravel models, automatically use them in urls and back-fill existing models.

Build & Test Status

Why?

Database IDs in URLs such as stackoverflow.com/users/12280 never quite feel ok to me

But at the same time, I didn't want to completely replace the database ID with a UUID, as some packages do - as I was nervous about how this might affect performance.

laravel-model-hash allows you to generate a short, random hash when an item is created while still using auto-incrementing IDs for database relationships.

How it works

This package provides a trait which - when attached to a model - creates a random string hash when new instances of the model are created.

The hash is created by shuffling an alphabet, taking the first length characters, and checking for uniqueness in the database (up to a maximum number of times). If a unique hash wasn't found within the maximum attempts, an exception of type UniqueHashNotFoundException will be thrown and the model instance will not be saved.

The package is configured either globally using a config file, or by defining model-specific properties.

Installation

You can install the package via Composer:

If you would like to tweak any of the package configuration, you must first publish the config file:

Usage

To add a hash to model, add the LaravelModelHash trait:

And create a migration to add a field to store the hash - by default, the field is called hash and has a length of 5:

You may add a unique and index flag for database performance improvements. If you're adding this trait to an existing model, you will need to use nullable() until all records have a hash.

Now, when new instances of the model are created, they will be assigned a random string.

Adding hashes to existing models

If you are adding this package to an existing installation, there is an artisan command to 'backfill' existing models. The syntax is:

This uses reflection to find all models (in app_path()) which extend the ModelHash trait, and adds hash values to any records where the hash is currently null.

If you would like to only run this for a specific model, use the --model (or -M) option - but remember to double-slash the namespace:

Configuration

There are three configurable parts to the hash:

And two other configuration properties

Each of these is set in the default configuration, which can be overridden in /config/laravelmodelhash.php (this must first be published - see the Installation section for details).

If you want to change these settings per model, they can be changed by adding the following model properties:

Thanks

I've gotten this far thanks to the following:


All versions of laravel-model-hash with dependencies

PHP Build Version
Package Version
No informations.
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 adamhopkinson/laravel-model-hash contains the following files

Loading the files please wait ....