1. Go to this page and download the library: Download io238/eloquent-encoded-ids 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/ */
namespace App\Models;
use Io238\EloquentEncodedIds\Traits\HasEncodedIds;
class User extends Model {
use HasEncodedIds;
// ..
}
class UserController extends Controller {
public function show(User $user)
{
return $user->id; // 1
}
}
class User extends Model {
use HasEncodedIds;
protected $prefix = 'usr';
}
return [
// Minimum length of encoded IDs
'length' => 5,
// Alphabet to be used to generate encoded IDs
// By default this list excludes ambiguous characters
'alphabet' => '123456789abcdefghikmnpqrstuvwxyz',
// Ignore uppercase/lowercase for encoded IDs
'case-insensitive' => true,
// Encryption salt
// Warning: changing the salt, will produce different encoded IDs
'salt' => env('APP_KEY'),
// Use a prefix to the encoded ID, to be able to recognize the model that the ID belongs to
'prefix' => true,
// Character used to separate the prefix from the encoded ID
'separator' => '_',
];