PHP code example of uthman / hashid

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

    

uthman / hashid example snippets


// Get Hash ID
$user = \App\User::first();
$user->hashed_id;   //x7LR5oQJleJX60yPpNWV

'key' => env('APP_KEY'),

use Illuminate\Database\Eloquent\Model;
use Erashdan\Hashid\Traits\Hashid;

class Post extends Model
{
    use Hashid;

$post = \App\Models\Post::first();
$post->hashed_id; //x7LR5oQJleJX60yPpNWV

$post = \App\Models\Post::FindOrFailHashed('x7LR5oQJleJX60yPpNWV');
$post->id; //1

    request()->validate([
        'post_id' => 'hashed_exists:' . \App\Post::class
    ]);
bash
php artisan vendor:publish --provider="Erashdan\Hashid\HashidServiceProvider" --tag="config"