PHP code example of erashdan / hashid

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

    

erashdan / 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\Post::first();
$post->hashed_id; //x7LR5oQJleJX60yPpNWV

$post = \App\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"