PHP code example of intelfric / laravel-encrypted-route

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

    

intelfric / laravel-encrypted-route example snippets


// config/app.php
'providers' => [
    // ...
    Intelfric\EncryptedRoute\EncryptedRouteServiceProvider::class,
],

'aliases' => [
    // ...
    'EncryptedUrl' => Intelfric\EncryptedRoute\Facades\EncryptedUrl::class,
],

return [
    // Route prefix for encrypted URLs
    'route_prefix' => 'encrypted',
    
    // Whether to redirect to original URL or dispatch internally
    'redirect_to_original' => false,
    
    // Default expiry time in minutes (null = no expiry)
    'default_expiry_minutes' => null,
    
    // Middleware applied to encrypted routes
    'middleware' => ['web'],
    
    // Cache decrypted routes for performance
    'cache_decrypted_routes' => false,
    
    // Cache TTL in seconds
    'cache_ttl' => 300,
    
    // Allowed routes (empty = all allowed)
    'allowed_routes' => [],
    
    // Routes that cannot be encrypted
    'excluded_routes' => [
        'login', 'logout', 'register'
    ],
];

// Generate encrypted URL
$encryptedUrl = encrypted_url('user.dashboard', ['id' => 123]);

// In Blade templates
<a href="{{ encrypted_url('user.profile', ['user' => $user->id]) }}">
    View Profile
</a>

use Intelfric\EncryptedRoute\Facades\EncryptedUrl;

$url = EncryptedUrl::generate('admin.settings', ['tab' => 'security']);

// In your routes or controllers
$url = Route::encryptedUrl('api.data', ['format' => 'json']);

// URL expires in 60 minutes
$temporaryUrl = encrypted_url_with_expiry('download.file', 60, ['file' => 'document.pdf']);

// URL expires at specific time
$expiry = now()->addHours(2);
$temporaryUrl = temporary_encrypted_url('admin.report', $expiry, ['type' => 'sales']);

// Check if encrypted path is valid
if (is_valid_encrypted_url($encryptedPath)) {
    // URL is valid and not expired
    echo "Valid URL";
}

use Intelfric\EncryptedRoute\Facades\EncryptedUrl;

// Generate with custom expiry
$url = EncryptedUrl::generateWithExpiry('user.dashboard', ['id' => 1], 30);

// Generate temporary URL
$expiry = now()->addDay();
$url = EncryptedUrl::temporary('download.report', $expiry, ['format' => 'pdf']);

// Validate encrypted path
$isValid = EncryptedUrl::isValid($encryptedPath);

// Redirect to original URL (user sees original URL)
'redirect_to_original' => true,

// Dispatch internally (user stays on encrypted URL)
'redirect_to_original' => false,

// URLs expire after 1 hour by default
'default_expiry_minutes' => 60,

// No default expiry
'default_expiry_minutes' => null,

// Only allow specific routes
'allowed_routes' => [
    'user.dashboard',
    'admin.panel',
],

// Prevent specific routes from being encrypted
'excluded_routes' => [
    'login',
    'register',
    'password.reset',
],

'cache_decrypted_routes' => true,
'cache_ttl' => 300, // 5 minutes

$adminUrl = encrypted_url('admin.users.index');
// Generates: /encrypted/eyJpdiI6... instead of /admin/users

$downloadUrl = encrypted_url_with_expiry('file.download', 30, ['file' => 'secret.pdf']);

$emailVerifyUrl = temporary_encrypted_url(
    'email.verify', 
    now()->addDay(), 
    ['token' => $token]
);

$apiUrl = encrypted_url('api.user.data', ['user' => $userId, 'format' => 'json']);
bash
php artisan vendor:publish --tag=encrypted-route-config