PHP code example of touhidurabir / laravel-model-uuid

1. Go to this page and download the library: Download touhidurabir/laravel-model-uuid library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

touhidurabir / laravel-model-uuid example snippets


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

class User extends Model {
    
    use HasUuid;
}

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

class User extends Model {
    
    use HasUuid;

    public function uuidable() : array {

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

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

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

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

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

User::disbaleUuidGeneration(true) // this will diable uuid generation temporarily for model
User::disbaleUuidGeneration(false) // this will enable uuid generation for model again
bash
php artisan vendor:publish --provider="Touhidurabir\ModelUuid\ModelUuidServiceProvider" --tag=config
bash
php artisan uuid:regenerate User,Profile