PHP code example of chistel / laravel-uniqueid

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

    

chistel / laravel-uniqueid example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Chistel\LaravelUniqueId\HasUniqueId;
use Chistel\LaravelUniqueId\UniqueIdOptions;

class UserModel extends Model
{
   use HasUniqueId;
    
   /**
	 * Get the route key for the model.
	 *
	 * @return string
	 */
	public function getRouteKeyName()
	{
	    return 'user_unique_id';  // this is the unique key column 
	}
	/**
	* Get the options for generating model uniqueId.
	*/
	public function getUniqueIdOptions() : UniqueIdOptions
	{
	  	return UniqueIdOptions::create()
	   	->saveUniqueIdTo('user_unique_id') // this is the unique key column 
	      	->uniqueIdShouldBeNoLongerThan(8);
	}
}