PHP code example of rawaby88 / muid

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

    

rawaby88 / muid example snippets


namespace App\Models;

use Rawaby88\Muid\Database\Eloquent\Model;

class Organization extends Model
{
    /**
	 * The "prefix" of the MUID.
	 *
	 * @var string
	 */
	protected $keyPrefix = 'org_';
}



namespace App\Models;

use \Rawaby88\Muid\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    /**
	 * The "prefix" of the MUID.
	 *
	 * @var string
	 */
	protected $keyPrefix = 'user_';
}



namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Rawaby88\Muid\Database\Eloquent\Muid;

class Organization extends Model
{
    use Muid;
    
    /**
	 * The "prefix" of the MUID.
	 *
	 * @var string
	 */
	protected $keyPrefix = 'organization_';
}

/**
 * The "prefix" of the MUID.
 *
 * @var string
 */
protected $keyPrefix = 'example_';




Schema::create( 'model_with_primaryMuid_test', function ( Blueprint $table ): void
{
    $table->primaryMuid( 'id' );
    $table->string( 'name' );
    $table->timestamps();
} );

Schema::create( 'model_with_muid_test', function ( Blueprint $table ): void
{
    $table->muid( 'id' )->primary();
    $table->string( 'name' );
    $table->timestamps();
} );

Schema::create( 'model_with_foreignMuid_test', function ( Blueprint $table ): void
{
    $table->muid( 'id' )->primary();
    $table->foreignMuid( 'model_with_muid_test_id' )->constrained( 'model_with_muid_test' );
    $table->timestamps();
} );

Schema::create( 'model_with_muidMorph_test', function ( Blueprint $table ): void
{
    $table->muid( 'id' )->primary();
    $table->muidMorphs( 'testable' );
    $table->timestamps();
} );

Schema::create( 'model_with_nullableMuidMorphs_test', function ( Blueprint $table ): void
{
    $table->muid( 'id' )->primary();
    $table->nullableMuidMorphs( 'testable' );
    $table->timestamps();
} );

Schema::create( 'model_without_muid_test', function ( Blueprint $table ): void
{
    $table->primaryMuid( 'id' );
    $table->timestamps();
} );

/*
|--------------------------------------------------------------------------
| Muid length
|--------------------------------------------------------------------------
|
| Here you can change the MUID length.
| remember that length |--------------------------------------------------------------------------
|
| Recommended not to change
|
*/
'alfa_small'   => 'abcdefghilkmnopqrstuvwxyz',
'alfa_capital' => 'ABCDEFGHILKMNOPQRSTUVWXYZ',
'digits'       => '0123456789',

/*
|--------------------------------------------------------------------------
| Capital Char options
|--------------------------------------------------------------------------
|
| Set it to FALSE if you wish not to use capital letters in the generated MUID
|
*/
'allow_capital' => TRUE,


php artisan vendor:publish --provider="Rawaby88\Muid\MuidServiceProvider"