2017 © Pedro PelĂĄez
 

library laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

image

emadadly/laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

  • Sunday, April 15, 2018
  • by EmadAdly
  • Repository
  • 3 Watchers
  • 48 Stars
  • 15,339 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 16 Forks
  • 1 Open issues
  • 11 Versions
  • 30 % Grown

The README.md

Laravel Uuid

Latest Version on Packagist Software License Quality Score Total Downloads, (*1)

A simple, automatic UUID generator for any model based on Laravel 5.5 and above, By using this package when each new entry you will get the following :, (*2)

  • Generate uuid automatically .
  • Assign it to uuid field in database automatically.
  • easy find it based uuid method.

What is a UUID?

A universally unique identifier (UUID) is a 128-bit number used to identify information in computer systems. is a 36 character long identifier made up of 32 alphanumeric characters with four hyphens in amongst it. For example:123E4567-E89b-12D3-A456-426655440000 containing letters and numbers. that will uniquely identify something. you can read more here, (*3)

What are the benefits?

  1. With distributed systems you can be pretty confident that the primary key’s will never collide., (*4)

  2. When building a large scale application when an auto increment primary key is not ideal., (*5)

  3. It makes replication trivial (as opposed to int’s, which makes it REALLY hard), (*6)

  4. Safe enough doesn’t show the user that you are getting information by id, for example https://example.com/user/25/settings, (*7)

Installation

To get started, require this package, (*8)

  • Via Composer

``` bash composer require emadadly/laravel-uuid, (*9)


- Via composer.json file Add the following to the `require` section of your projects `composer.json` file. ``` php "emadadly/laravel-uuid": "1.*",

Run composer update to download the package, (*10)

``` bash composer update, (*11)


Finally, you'll also need to add the ServiceProvider **Laravel 5.5 and above** Uses package auto discovery feature, no need to edit the config/app.php file. **Laravel 5.4 and below** You need to add the ServiceProvider in `config/app.php` with the following ``` php 'providers' => [ ... Emadadly\LaravelUuid\LaravelUuidServiceProvider::class, ],

You could also publish the config file:, (*12)

``` bash php artisan vendor:publish --provider="Emadadly\LaravelUuid\LaravelUuidServiceProvider", (*13)


and set your default_uuid_column setting, if you have an app-wide default. Our package assumes the column is `uuid` by default. If you want to replace the default `id` follow [these steps.](#replacing-default-id-with-uuid) ## Usage #### Migrations When using the migration you should add `uuid` as column type, and set the name it the same name in the `config/uuid.php` file. ``` php $table->uuid('uuid');

it's will create column uuid name and a char(36) inside of our database schema, To be ready to receive Uuids., (*14)

Simply, the schema seems something like this., (*15)

``` php Schema::create('users', function (Blueprint $table) {, (*16)

$table->increments('id'); $table->uuid('uuid'); .... .... $table->timestamps(); });, (*17)



#### Models Use this trait in any model. To set up a model to using Uuid, simply use the Uuids trait: ``` php use Illuminate\Database\Eloquent\Model; use Emadadly\LaravelUuid\Uuids; class ExampleModel extends Model { use Uuids; .... }

Controller

When you create a new instance of a model which uses Uuids, our package will automatically add Uuid., (*18)

``` php // 'Uuid' will automatically generate and assign id field. $model = ExampleModel::create(['name' => 'whatever']);, (*19)


Also when use show, update or delete method inside the Controller, it very easy to implement through `ExampleModel::uuid()` scope method ``` php public function show($uuid) { $example = ExampleModel::uuid($uuid); return response()->json(['example' => $example]); }

Replacing default ID with UUID

If you want to replace the default id column with the uuid be sure to set 'default_uuid_column' => 'uuid', to 'default_uuid_column' => 'id', in the config\uuid.php file., (*20)

On your migration(s), change the id column type from increments to uuid as well as manually adding the primary key. Note: This also applies to model relationship columns, if the related model is using an UUID, the column type should reflect that, (*21)

``` php Schema::create('users', function (Blueprint $table) {, (*22)

$table->uuid('id')->unique(); $table->primary('id'); .... // related model uses UUID, must change type $table->uuid('model_id'); .... $table->timestamps(); });, (*23)


Then on the model(s) you will need to set the incrementing flag to false. ``` php use Illuminate\Database\Eloquent\Model; use Emadadly\LaravelUuid\Uuids; class ExampleModel extends Model { use Uuids; .... /** * Indicates if the IDs are auto-incrementing. * * @var bool */ public $incrementing = false; .... }

Support

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

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., (*25)

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

License

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

The Versions

15/04 2018

dev-master

9999999-dev https://github.com/emadadly/laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid guid generator laravel-uuid laravel uuid emadadly laravel-guid

15/04 2018

v1.2.5

1.2.5.0 https://github.com/emadadly/laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid guid generator laravel-uuid laravel uuid emadadly laravel-guid

14/04 2018

v1.2.4

1.2.4.0 https://github.com/emadadly/laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid guid generator laravel-uuid laravel uuid emadadly laravel-guid

13/04 2018

v1.2.3

1.2.3.0 https://github.com/emadadly/laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid guid generator laravel-uuid laravel uuid emadadly laravel-guid

17/02 2018

v1.2.2

1.2.2.0 https://github.com/emadadly/laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid guid generator laravel-uuid laravel uuid emadadly laravel-guid

03/09 2017

v1.2.1

1.2.1.0 https://github.com/emadadly/laravel-uuid

laravel uuid a simple, automatic UUID generator for any model based on Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid guid generator laravel-uuid laravel uuid emadadly laravel-guid

21/06 2017

v1.2

1.2.0.0 https://github.com/emadadly/laravel-uuid

A simple, automatic UUID generator for any model based on Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid guid generator laravel-uuid laravel uuid emadadly laravel-guid

16/02 2017

v1.1

1.1.0.0 https://github.com/emadadly/laravel-uuid

A simple, automatic UUID generator for any model based on Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid guid generator laravel-uuid laravel uuid emadadly laravel-guid

16/02 2017

v1.1-beta

1.1.0.0-beta https://github.com/emadadly/laravel-uuid

A simple, automatic UUID generator for any model based on Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid guid generator laravel-uuid laravel uuid emadadly laravel-guid

15/02 2017

v1.0.1

1.0.1.0 https://github.com/emadadly/laravel-uuid

A simple, automatic UUID generator for any model based on Laravel.

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel uuid guid generator laravel-uuid laravel uuid emadadly laravel-guid

14/02 2017

v1.0

1.0.0.0 https://github.com/emadadly/larauuid

:UUID auto generator for Laravel 5

  Sources   Download

MIT

The Requires

 

The Development Requires

by :Emad Adly

laravel uuid guid generator emadadly larauuid