A laravel package to attach uuid to model classes

Overview

Laravel Model UUID

A simple package to generate model uuid for laravel models

Installation

Require the package using composer:

composer require touhidurabir/laravel-model-uuid

To publish the config file:

php artisan vendor:publish --provider="Touhidurabir\ModelUuid\ModelUuidServiceProvider" --tag=config

Usage

Use the trait HashUuid in model where uuid needed to attach

use Touhidurabir\ModelUuid\HasUuid;
use Illuminate\Database\Eloquent\Model;

class User extends Model {
    
    use HasUuid;
}

By default this package use the column name uuid as for the uuid attach and preform it on model creating event . But these configurations can be changed form the model-uuid.php config file.

Also possible to override the uuid column and attaching event from each of the model . to do that need to place the following method in the model :

use Touhidurabir\ModelUuid\HasUuid;
use Illuminate\Database\Eloquent\Model;

class User extends Model {
    
    use HasUuid;

    public function uuidable() : array {

        return [
            'column' => 'uuid',
            'event'  => 'created',
        ];
    }
}

Make sure to the put the uuid colun name in migration file

$table->string('uuid')->nullable()->unique()->index();

Or can be used with the combination of model-uuid config as such:

$table->string(config('model-uuid.column'))->nullable()->unique()->index();

This package also include some helper method that make it easy to find model records via UUID. for example

User::byUuid($uuid)->where('active', true)->first(); // single uuid
User::byUuid([$uuid1, $uuid2])->where('active', true)->get(); // multiple uuid

Or simple and direct find

User::findByUuid($uuid); // single uuid
User::findByUuid([$uuid1, $uuid2]); // multiple uuid

The package also provide a bit of safe guard by checking if the model table has the given uuid column .

If the uuid column not found for model table schema, it will not create and attach an uuid.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

You might also like...
Laravel-model-mapper - Map your model attributes to class properties with ease.
Laravel-model-mapper - Map your model attributes to class properties with ease.

Laravel Model-Property Mapper This package provides functionality to map your model attributes to local class properties with the same names. The pack

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

🏭This package lets you create factory classes for your Laravel project.
🏭This package lets you create factory classes for your Laravel project.

Laravel Factories Reloaded 🏭 This package generates class-based model factories, which you can use instead of the ones provided by Laravel. Laravel 8

Package with small support traits and classes for the Laravel Eloquent models

Contains a set of traits for the eloquent model. In future can contain more set of classes/traits for the eloquent database.

A Laravel package that adds a simple image functionality to any Laravel model
A Laravel package that adds a simple image functionality to any Laravel model

Laraimage A Laravel package that adds a simple image functionality to any Laravel model Introduction Laraimage served four use cases when using images

Laravel comments - This package enables to easily associate comments to any Eloquent model in your Laravel application

Laravel comments - This package enables to easily associate comments to any Eloquent model in your Laravel application

This Laravel package merges staudenmeir/eloquent-param-limit-fix and staudenmeir/laravel-adjacency-list to allow them being used in the same model.

This Laravel package merges staudenmeir/eloquent-param-limit-fix and staudenmeir/laravel-adjacency-list to allow them being used in the same model.

Save Model is a Laravel package that allows you to save data in the database in a new way.

Save Model is a Laravel package that allows you to save data in the database in a new way. No need to worry about $guarded and $fillable properties in the model anymore. Just relax an use Save Model package.

A simple laravel package to handle multiple key based model route binding

Laravel Model UUID A simple package to handle the multiple key/column based route model binding for laravel package Installation Require the package u

Releases(1.1.1)
Owner
null
This package provides a trait that will generate a unique uuid when saving any Eloquent model.

Generate slugs when saving Eloquent models This package provides a trait that will generate a unique uuid when saving any Eloquent model. $model = new

Abdul Kudus 2 Oct 14, 2021
Generate UUID for a Laravel Eloquent model attribute

Generate a UUIDv4 for the primary key or any other attribute on an Eloquent model.

Alex Bouma 4 Mar 1, 2022
This package lets you add uuid as primary key in your laravel applications

laravel-model-uuid A Laravel package to add uuid to models Table of contents Installation Configuration Model Uuid Publishing files / configurations I

salman zafar 10 May 17, 2022
A laravel package to handle sanitize process of model data to create/update model records.

Laravel Model UUID A simple package to sanitize model data to create/update table records. Installation Require the package using composer: composer r

null 66 Sep 19, 2022
A laravel package to generate model hashid based on model id column.

Laravel Model Hashid A package to generate model hash id from the model auto increment id for laravel models Installation Require the package using co

Touhidur Rahman 13 Jan 20, 2022
A package to filter laravel model based on query params or retrieved model collection

Laravel Filterable A package to filter laravel model based on query params or retrived model collection. Installation Require/Install the package usin

Touhidur Rahman 17 Jan 20, 2022
Use UUID or Ulid as optional or primary key in Laravel.

Laravel OptiKey Use UUID or Ulid as optional or primary key in Laravel. composer require riipandi/laravel-optikey This package adds a very simple trai

Aris Ripandi 33 Nov 4, 2022
Use auto generated UUID slugs to identify and retrieve your Eloquent models.

Laravel Eloquent UUID slug Summary About Features Requirements Installation Examples Compatibility table Alternatives Tests About By default, when get

Khalyomede 25 Dec 14, 2022
A simple drop-in solution for providing UUID support for the IDs of your Eloquent models.

Introduction A simple drop-in solution for providing UUID support for the IDs of your Eloquent models. Both v1 and v4 IDs are supported out of the box

GoldSpec Digital 501 Jan 4, 2023
Collection of the Laravel/Eloquent Model classes that allows you to get data directly from a Magento 2 database.

Laragento LAravel MAgento Micro services Magento 2 has legacy code based on abandoned Zend Framework 1 with really ugly ORM on top of outdated Zend_DB

Egor Shitikov 87 Nov 26, 2022