Download the PHP package parables/laravel-model-nanoid without Composer

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

Laravel Model UUIDs

Introduction

Huge thanks to Micheal Dyrynda, whose work inspired me to create this package based on laravel-model-nanoid but uses NanoId instead of UUID.

Why NanoID?

<img src="https://ai.github.io/nanoid/logo.svg" align="right" alt="Nano ID logo by Anton Lovchikov" width="180" height="94">

A tiny, secure, URL-friendly, unique string ID generator for PHP.

This package is PHP implementation of ai's nanoId. Read its documentation for more information.

Note: this package explicitly does not disable auto-incrementing on your Eloquent models. In terms of database indexing, it is generally more efficient to use auto-incrementing integers for your internal querying. Indexing your nanoId column will make lookups against that column fast, without impacting queries between related models.

Installation

This package is installed via Composer. To install, run the following command.

Code Samples

In order to use this package, you simply need to import and use the trait within your Eloquent models.

It is assumed that you already have a field named nanoId in your database, which is used to store the generated value. If you wish to use a custom column name, for example if you want your primary id column to be a NanoID, you can define a static nanoIdColumn method in your model.

Use NanoId as primary key

If you choose to use a NanoID as your primary model key (id), then use GeneratesNanoIdAsPrimaryKey trait on your model.

And update your migrations

This trait also provides a query scope which will allow you to easily find your records based on their NanoID, and respects any custom field name you choose.

Route model binding

Should you wish to leverage implicit route model binding on your nanoId field, you may use the BindsOnNanoId trait, which will use the value returned by nanoIdColumn(). Should you require additional control over the binding, you may override the getRouteKeyName method directly.

You can generate multiple NanoID columns for a model by returning an array of column names in the nanoIdColumns() method.

If you use the nanoIdColumns() method, then first element in the array must be the value returned by the nanoIdColumn() method which by default is nanoId. If you overwrite the nanoIdColumn() method, put its return value as the first element in the nanoIdColumns() return array.

When querying using the whereNanoId() scope, the default column - specified by nanoIdColumn() will be used.

The nanoIdColumns must return an array. You can customize the generated NanoId for each column by using an associative array where the key is the column name and the value is an array with an optional int size and string alphabet keys.

The following options are available for the alphabet key.

Support

If you are having general issues with this package, feel free to contact me on Twitter.

If you believe you have found an issue, please report it using the GitHub issue tracker, or better yet, fork the repository and submit a pull request.

If you're using this package, I'd love to hear your thoughts. Thanks!

Treeware

You're free to use this package, but if it makes it to your production environment you are required to buy the world a tree.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to plant trees. If you support this package and contribute to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees here

Read more about Treeware at treeware.earth

Tools

Credits


All versions of laravel-model-nanoid with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/database Version ^10.0|^11.0
illuminate/events Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.0
snortlin/nano-id Version ^1.0.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 parables/laravel-model-nanoid contains the following files

Loading the files please wait ....