1. Go to this page and download the library: Download macmotp/codegen-laravel 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/ */
macmotp / codegen-laravel example snippets
use Illuminate\Database\Eloquent\Model;
use Macmotp\HasCodegen;
class Foo extends Model
{
use HasCodegen;
protected $fillable = [
'title',
'reference',
];
/**
* Attribute of the model used to generate the code
*
* @return string
*/
protected function buildCodeFrom(): string
{
return $this->title;
}
/**
* Column used to save the unique code
*
* @return string
*/
protected function getCodeColumn(): string
{
return 'reference';
}
/**
* Get char length of the code
*
* @return int
*/
protected function getCodeLength(): int
{
return 12;
}
/**
* Force to prepend this portion of string in the code
*
* @return string
*/
protected function prependToCode(): string
{
return 'PR';
}
/**
* Force to append this portion of string in the code
*
* @return string
*/
protected function appendToCode(): string
{
return 'AP';
}
/**
* Get the sanitize level to apply
*
* @return int
*/
protected function getCodeSanitizeLevel(): int
{
return 3; // Level High
}
}