2017 © Pedro Peláez
 

library laravel-eloquent-hashids

Automatically generate hashids in Laravel for a new Eloquent Model.

image

naabster/laravel-eloquent-hashids

Automatically generate hashids in Laravel for a new Eloquent Model.

  • Tuesday, April 25, 2017
  • by naabster
  • Repository
  • 1 Watchers
  • 12 Stars
  • 6,447 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 3 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

Laravel 5 Eloquent Hashids

Laravel 5 Eloquent Model trait for automatically generating and persistently saving Hashids for new models.
Uses @vinkla's Laravel 5 Hashids package., (*1)

Latest Stable Version License, (*2)

Installation

Require this package, with Composer, in the root directory of your project., (*3)

composer require naabster/laravel-eloquent-hashids:~1.0

You should first install @vinkla's Laravel 5 Hashids package according to their installation instructions., (*4)

Usage

Use the EloquentHashids trait on your model:, (*5)


use Illuminate\Database\Eloquent\Model; use Naabster\EloquentHashids\EloquentHashids; class Book extends Model { use EloquentHashids; // Rest of your eloquent model }

Configuration

By default the following configuration is used:, (*6)

Hashids Connection

The default Hashids Connection is table.<tablename>, so for example for the Book model it would be table.books. You can set a different connection for your model with static::getHashidConnection():, (*7)


use Illuminate\Database\Eloquent\Model; use Naabster\EloquentHashids\EloquentHashids; class Book extends Model { use EloquentHashids; public static function getHashidConnection(Model $model) { return 'someconnection'; } }

Make sure you set your connections in your config/hashids.php config file (comes with @vinkla's Laravel 5 Hashids package)!, (*8)

Column Name

By default the Hashid column is named uid. You can set a different column name for your model with static::getHashidColumn():, (*9)


use Illuminate\Database\Eloquent\Model; use Naabster\EloquentHashids\EloquentHashids; class Book extends Model { use EloquentHashids; public static function getHashidColumn(Model $model) { return 'hashid'; } }

Attention, (*10)

This package generates Hashids for new models and saves them to a column in your database table! To be able to do that, this column must exist in your table.
You should add this column to your model with a database migration., (*11)

Encoding Value

By default the Value/Number for your Hashid is the primary Key attribute of your model (defaults to id). You can adjust that any way you want, just make sure it is Hashids compatible. Just return another value from static::getHashidEncodingValue():, (*12)


use Illuminate\Database\Eloquent\Model; use Naabster\EloquentHashids\EloquentHashids; class Book extends Model { use EloquentHashids; public static function getHashidEncodingValue(Model $model) { return $model->myId; } }

Example

In this example we generate Hashids with the connection bookHashids, for column hashid and with an encoding value of an array:, (*13)


use Illuminate\Database\Eloquent\Model; use Naabster\EloquentHashids\EloquentHashids; class Book extends Model { use EloquentHashids; public static function getHashidConnection(Model $model) { return 'bookHashids'; } public static function getHashidColumn(Model $model) { return 'hashid'; } public static function getHashidEncodingValue(Model $model) { return [$model->id, $model->foreign_key]; } }

License

The Laravel 5 Eloquent Hashids package is open-sourced software licensed under the MIT license., (*14)

The Versions

25/04 2017

dev-master

9999999-dev

Automatically generate hashids in Laravel for a new Eloquent Model.

  Sources   Download

MIT

The Requires

 

by Michael Naab

laravel eloquent hashids hashid

25/04 2017

1.0.4

1.0.4.0

Automatically generate hashids in Laravel for a new Eloquent Model.

  Sources   Download

MIT

The Requires

 

by Michael Naab

laravel eloquent hashids hashid

21/09 2016

1.0.3

1.0.3.0

Automatically generate hashids in Laravel for a new Eloquent Model.

  Sources   Download

MIT

The Requires

 

by Michael Naab

laravel eloquent hashids hashid

15/09 2016

1.0.2

1.0.2.0

Automatically generate hashids in Laravel for a new Eloquent Model.

  Sources   Download

MIT

The Requires

 

by Michael Naab

laravel eloquent hashids hashid

22/07 2015

1.0.1

1.0.1.0

Automatically generate hashids in Laravel for a new Eloquent Model.

  Sources   Download

MIT

The Requires

 

by Michael Naab

laravel eloquent hashids hashid

29/04 2015

1.0.0

1.0.0.0

Automatically generate hashids in Laravel for a new Eloquent Model.

  Sources   Download

MIT

The Requires

 

by Michael Naab

laravel eloquent hashids hashid