swapneal-dev/laravel-hasuuid

Trait for add uuid in models

dev-main 2022-06-23 10:56 UTC

This package is auto-updated.

Last update: 2024-11-23 16:11:07 UTC


README

Install using composer

composer require swapneal-dev/laravel-hasuuid

This package adds a very simple trait to automatically generate a UUID for your Models.

Simply add the "SwapnealDev\LaravelHasUuid\HasUuid;" trait to your model:

<?php

namespace App;

use SwapnealDev\LaravelHasUuid\HasUuid;
use Illuminate\Database\Eloquent\Model;

class Project extends Model
{

    use HasUuid;

}

It supports any column name for uuid default is uuid.
add below line to your model.

public string $uuidKey = 'uuid_key_name';

You can find by uuid in model;

$project = Project::findByUuid($uuid);

It will return Model object or empty object.