1. Go to this page and download the library: Download rawilk/human-keys 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/ */
rawilk / human-keys example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Rawilk\HumanKeys\Concerns\HasHumanKey;
class Post extends Model
{
use HasHumanKey;
}
namespace App\Generators;
use Rawilk\HumanKeys\Contracts\KeyGenerator;
class CustomGenerator implements KeyGenerator
{
public function generate(?string $prefix = null): string
{
// Generate your ID here...
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Rawilk\HumanKeys\Concerns\HasHumanKey;
class Post extends Model
{
use HasHumanKey;
public static function humanKeyPrefix() : string
{
// You should omit an underscore at the end of the prefix, as it will be added automatically
// by the generator.
return 'custom_prefix';
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Rawilk\HumanKeys\Concerns\HasHumanKey;
class Post extends Model
{
use HasHumanKey;
public function humanKeys(): array
{
return ['human_key'];
}
}