PHP code example of lemaur / laravel-human-id

1. Go to this page and download the library: Download lemaur/laravel-human-id 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/ */

    

lemaur / laravel-human-id example snippets


// database\migrations\create_posts_table.php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('posts', static function (Blueprint $table) {
            $table->id();
            
            $table->huid(); // <-- declare "huid" field
            
            // other fields...
        });
    }
}

// app\Models\Post.php

namespace App\Models;

use \Illuminate\Database\Eloquent\Model;
use \Lemaur\HumanId\Concerns\HasHuids;

class Post extends Model
{
    use HasHuids; // <-- import trait
    
    /** @var string */
    private const HUID_PREFIX = 'post'; // <-- declare prefix (max 4 characters)
}

// this will generate a huid like --> post_01h554vp2prg6zfayagh83ccx7