CodeIgniter Forums
UUID with support for Model and Entity - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34)
+--- Thread: UUID with support for Model and Entity (/showthread.php?tid=76517)



UUID with support for Model and Entity - michalsn - 05-20-2020

Hi!

I created a small package that makes it easy to work with UUID in CodeIgniter 4 - https://github.com/michalsn/codeigniter4-uuid

This package work with different versions of UUID - starting from version 1 and up to version 6 - but everything is integrated into a model class to make it work smoothly. So we basically use it like a "normal" model class. We can also store UUID in the database in a byte format to optimize the used space.

Let me get you a small example of how would using UUID as a primary key in our model would look like:

PHP Code:
<?php

namespace App\Models;

use 
Michalsn\Uuid\UuidModel;

class 
Project1Model extends UuidModel
{
    protected $table      'projects_1';
    protected $primaryKey 'id';

    protected $returnType 'array';
    protected $useSoftDeletes true;

    protected $allowedFields = ['name''description''created_at''updated_at''deleted_at'];

    protected $useTimestamps true;

    protected $validationRules = [
        'name' => 'required|min_length[3]',
        'description' => 'required',
    ];


Out model have to extend UuidModel instead of Model and that's it. More detailed info is available in the project repo.


RE: UUID with support for Model and Entity - JazMagno - 05-26-2020

Thanks, very usefull. 

When do you think you have a release version?


RE: UUID with support for Model and Entity - michalsn - 06-08-2020

Hi there!

Sorry that I'm responding so late but I didn't get any notification about new response for this thread.

First official release? Probably shortly after next CI version will be released... so probably next month.