承接 brrittoo/url-encoder 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

brrittoo/url-encoder

最新稳定版本:v2.0.0

Composer 安装命令:

composer require brrittoo/url-encoder

包简介

Laravel package for URL parameter encoding

README 文档

README

Latest Version Total Downloads License

Secure URL parameter encryption for Laravel applications. Protect sensitive data in your routes with AES-128-CTR encryption.

Features

  • Automatic encryption/decryption of route parameters
  • Seamless integration with Laravel's URL generation
  • AES-128-CTR encryption with random IVs
  • URL-safe base64 encoding
  • Configurable route groups and exclusions
  • JavaScript compatibility
  • Optional full source publish for local development

Installation

Install via Composer:

composer require brrittoo/url-encoder

Publish the config file:

php artisan vendor:publish --provider="Brrittoo\UrlEncoder\UrlEncoderServiceProvider" --tag="url-encoder-config"

Configuration

Set these in your .env:

URL_ENCODE_ENABLE=true
URL_ENCRYPTION_SECRET_KEY=your-32-character-secret-key-here

Edit config/url-encoder.php to customize:

<?php

return [
		/*
		|--------------------------------------------------------------------------
		| Enabled Route Groups
		|--------------------------------------------------------------------------
		|
		| Route groups where URL encoding should be automatically applied
		|
		*/
		'enable_route_groups' => [
			'web',
			'api',
		],
		
		/*
		|--------------------------------------------------------------------------
		| Excluded Routes
		|--------------------------------------------------------------------------
		|
		| Route names that should skip URL encoding
		|
		*/
		'exclude_routes' => [
			'login',
			'register'
		],
		
		/*
		|--------------------------------------------------------------------------
		| Manual Middleware Registration
		|--------------------------------------------------------------------------
		|
		| Manually specify where to apply the middleware if not using route groups
		| Options: 'global', 'none', or array of specific middleware groups
		|
		*/
		'manual_middleware_registration' => 'auto',
		
		/*
		|--------------------------------------------------------------------------
		| Enable Encoding
		|--------------------------------------------------------------------------
		|
		| Master switch for URL encoding functionality
		|
		*/
		'is_encoding_enable' => env('URL_ENCODE_ENABLE', false),
		
		/*
		|--------------------------------------------------------------------------
		| Encryption Secret Key
		|--------------------------------------------------------------------------
		|
		| Key used for encrypting/decrypting URL parameters
		|
		*/
		'url_encryption_secret_key' => env('URL_ENCRYPTION_SECRET_KEY'),
	];

Manual Control the middleware

If you want full control, change in config/url-encoder.php:

'manual_middleware_registration' => 'none',

Add the middleware alias to your app/Http/Kernel.php:

protected $routeMiddleware = [
    // Other middleware...
    'url-encode' => \Brrittoo\UrlEncoder\Middleware\UrlManipulationMiddleware::class,
];

you can also use like this way

protected $middlewareGroups = [
    'web' => [
        // existing middleware...
        \Brrittoo\UrlEncoder\Middleware\UrlManipulationMiddleware::class,
    ],
];

Usage

Config-cache Command:

php artisan config:cache

Basic Usage

Route::get('/project/{project_id}/task/{task_id}', function ($project_id, $task_id) {
    // Parameters are automatically decrypted
})->name('project.task.show');

JavaScript Integration

PHP Side (Controller/Blade):

$urlData = encryptedRoute('project.task.show', ['project_id', 'task_id']);

JavaScript Side:

<script>
   let action_url = @json($urlData['url'])
           .replace(@json($urlData['placeholders']['project_id']), projectId)
           .replace(@json($urlData['placeholders']['task_id']), taskId);

   fetch(action_url)
           .then(response => response.json())
           .then(data => console.log(data));
</script>

Methods

  • encryptedRouteJS(string $routeName, array $paramNames)
$urlData = encryptedRouteJS('route.name', ['param1', 'param2']);
// Returns: ['url' => '...', 'placeholders' => [...]]

License

This package is open-source and licensed under the MIT License.

Author

Ataul Galib
Email: ataul.gonigalib@gmail.com

统计信息

  • 总下载量: 6
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-28