All Projects → EmadAdly → Laravel Uuid

EmadAdly / Laravel Uuid

Licence: mit
laravel uuid a simple, automatic UUID generator for any model based on Laravel

Labels

Projects that are alternatives of or similar to Laravel Uuid

Uuid Readable
Generate Easy to Remember, Readable UUIDs, that are Shakespearean and Grammatically Correct Sentences 🥳
Stars: ✭ 616 (+498.06%)
Mutual labels:  uuid
Instauuid
Instagram-Style Compact UUID generator library for Node.js
Stars: ✭ 31 (-69.9%)
Mutual labels:  uuid
Uuid Creator
A Java library for generating and handling RFC-4122 UUIDs.
Stars: ✭ 78 (-24.27%)
Mutual labels:  uuid
Uuid Doctrine
Allow the use of a ramsey/uuid UUID as Doctrine field type.
Stars: ✭ 751 (+629.13%)
Mutual labels:  uuid
Session Token
Secure, efficient, simple random session token generation
Stars: ✭ 12 (-88.35%)
Mutual labels:  uuid
Ar Uuid
Override migration methods to support UUID columns without having to be explicit about it.
Stars: ✭ 41 (-60.19%)
Mutual labels:  uuid
Laravel Binary Uuid
Optimised binary UUIDs in Laravel
Stars: ✭ 523 (+407.77%)
Mutual labels:  uuid
Uuid Random
Fastest UUID with cryptographic PRNG for JS
Stars: ✭ 87 (-15.53%)
Mutual labels:  uuid
Node Scalable Blob Store
A file system blob store that is designed to prevent conflicts when used with a distributed file system or storage area network
Stars: ✭ 31 (-69.9%)
Mutual labels:  uuid
Hotelsystem
🏨TopView工作室一轮考核项目:一个酒店管理系统,提供查看房间,对房间进行模糊查询,预订房间,个人信息管理,房间和酒店信息管理(管理员)等功能,后台使用Java,tomcat,mysql,servlet,jsp实现,没有使用任何框架
Stars: ✭ 78 (-24.27%)
Mutual labels:  uuid
Ordered Uuid
Reorganizes UUIDs for the purpose of fast indexing and searching by a database.
Stars: ✭ 5 (-95.15%)
Mutual labels:  uuid
Go Uuid
A wrapper for Linux kernel UUID v4 generator.
Stars: ✭ 26 (-74.76%)
Mutual labels:  uuid
Kirby3 Autoid
Automatic unique ID for Pages, Files and Structures including performant helpers to retrieve them. Bonus: Tiny-URL.
Stars: ✭ 58 (-43.69%)
Mutual labels:  uuid
Timeflake
Timeflake is a 128-bit, roughly-ordered, URL-safe UUID.
Stars: ✭ 669 (+549.51%)
Mutual labels:  uuid
Uuid Shortener
A simple RFC 4122 UUID shortener library. Change your long 36 chars long ID into it's shorter equivalent.
Stars: ✭ 81 (-21.36%)
Mutual labels:  uuid
Shortuuid
🍄 A generator library for concise, unambiguous and URL-safe UUIDs
Stars: ✭ 603 (+485.44%)
Mutual labels:  uuid
Ksuid
Java implementation of K-Sortable Globally Unique IDs
Stars: ✭ 35 (-66.02%)
Mutual labels:  uuid
Fcuuid
iOS UUID / Universally Unique Identifiers library as alternative to UDID and identifierForVendor. 📱
Stars: ✭ 1,387 (+1246.6%)
Mutual labels:  uuid
Echo360
Commandline tool for automated downloads of echo360 videos hosted by university
Stars: ✭ 81 (-21.36%)
Mutual labels:  uuid
Ble
✨Android BLE基础操作框架,基于回调,操作简单。包含扫描、多连接、广播包解析、服务读写及通知等功能。
Stars: ✭ 1,183 (+1048.54%)
Mutual labels:  uuid

Laravel Uuid

Latest Version on Packagist Software License Quality Score Total Downloads

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 :

  • 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

What are the benefits?

  1. With distributed systems you can be pretty confident that the primary key’s will never collide.

  2. When building a large scale application when an auto increment primary key is not ideal.

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

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

Installation

To get started, require this package

  • Via Composer
 composer require emadadly/laravel-uuid
  • Via composer.json file

Add the following to the require section of your projects composer.json file.

"emadadly/laravel-uuid": "1.*",

Run composer update to download the package

 composer update

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

'providers' => [
   ...
   Emadadly\LaravelUuid\LaravelUuidServiceProvider::class,
],

You could also publish the config file:

php artisan vendor:publish --provider="Emadadly\LaravelUuid\LaravelUuidServiceProvider"

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.

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.

$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.

Simply, the schema seems something like this.

Schema::create('users', function (Blueprint $table) {

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

Models

Use this trait in any model.

To set up a model to using Uuid, simply use the Uuids trait:

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.

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

Also when use show, update or delete method inside the Controller, it very easy to implement through ExampleModel::uuid() scope method

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.

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

Schema::create('users', function (Blueprint $table) {

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

Then on the model(s) you will need to set the incrementing flag to false.

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.

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!

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].