PHP code example of swindon / filament-hashids

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

    

swindon / filament-hashids example snippets


use Swindon\FilamentHashids\Traits\HasHashid;

class User extends Authenticatable
{
    use HasHashid;
    
    // ...
}

$user = User::find(1);
echo $user->getHashid();

$user = User::findHashId($hashId);
$users = User::whereHashId($hashId)->get();

use Filament\Panel;
use Filament\PanelProvider;
use Swindon\FilamentHashids\Middleware\FilamentHashidsMiddleware;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->middleware([
                FilamentHashidsMiddleware::class, // Decodes Hashids for all routes in this panel
                // ...existing code...
            ]);
    }
}

use Filament\Resources\Resource;

class UserResource extends Resource
{
    public static array|string $routeMiddleware = [
        'filament-hashids', // Ensures Hashids are decoded for this resource's routes
    ];
}
bash
php artisan install:filament-hashids