PHP code example of reishou / unique-identity

1. Go to this page and download the library: Download reishou/unique-identity 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/ */

    

reishou / unique-identity example snippets




namespace App;

use Illuminate\Database\Eloquent\Model;
use Reishou\UniqueIdentity\HasUid;

class YourModel extends Model
{
    use HasUid;
}

// $listAttributes contain 10 elements, every element is an array attributes will insert to database.
$listAttributes = [...]; 
// array $ids contains 10 uid
$ids = YourModel::uid(count($listAttributes));
// set ids to attributes
$listAttributes = collect($listAttributes)->map(function ($attributes, $index) use ($ids) {
    $attributes['id']         = $ids[$index];
    $attributes['created_at'] = now();
    $attributes['updated_at'] = now();
    
    return $attributes;
})
    ->toArray();
// insert to database
YourModel::insert($listAttributes);
shell
php artisan vendor:publish --provider="Reishou\UniqueIdentity\UidServiceProvider"
shell
php artisan uid:table

php artisan migrate