sulimanbenhalim/route-hints
Composer 安装命令:
composer require sulimanbenhalim/route-hints
包简介
Intelligent 'did you mean?' route suggestions for Laravel 404 errors
关键字:
README 文档
README
Laravel 404 errors → intelligent route suggestions
Install
composer require sulimanbenhalim/route-hints
Usage
Routes Control
All routes discoverable by default
Route::get('/users', UserController::class); // ✓ Suggested Route::get('/posts', PostController::class)->discoverable(); // ✓ Explicitly suggested Route::get('/admin', AdminController::class)->hidden(); // ✗ Never suggested
Custom Keywords
Route::get('/dashboard', HomeController::class) ->withHints(['home', 'control-panel']);
/home → suggests /dashboard
Parameterized Routes
Route::get('/posts/{post}', PostController::class) ->includeParameterized(['post' => 'welcome']);
/post → suggests /posts/welcome
Programmatic Access
$suggestions = app('route-hints')->findSuggestions(request()); $suggestions = RouteHints::findSuggestions(request());
Responses
| Request Type | Response |
|---|---|
| HTML | Default Laravel 404 view with clickable suggestions |
| JSON | {"suggestions": [{"url": "http://app.test/users"}]} |
| Auto-redirect | Direct redirect when similarity > threshold |
Auto-Redirect Setup
Required for session-based auto-redirect
Add to bootstrap/app.php:
->withMiddleware(function (Middleware $middleware): void { $middleware->prepend(\Illuminate\Session\Middleware\StartSession::class); }) // Or running this command, mentioned blow in the docs // php artisan route-hints:setup-session
Auto-redirect Data:
// Query method adds URL parameters: // /users?route_corrected_from=%2Fuser&similarity=90.5&route_name=users.index // Session method stores structured data: session('route_hints_correction') = [ 'original_path' => '/user', 'corrected_path' => '/users', 'similarity_percentage' => 90.5, 'route_name' => 'users.index', 'corrected_at' => '2024-01-15T...' ];
Configuration
php artisan vendor:publish --tag=route-hints-config
All Settings
| Setting | Default | Description |
|---|---|---|
enabled |
true |
Enable/disable route hints |
max_distance |
5 |
Levenshtein distance limit |
max_suggestions |
3 |
How many to show |
default_discoverable |
true |
Routes discoverable by default |
excluded_patterns |
[] |
Never suggest these routes |
cache_ttl |
3600 |
Cache discoverable routes (seconds) |
show_similarity_percentage |
false |
Show similarity % in responses |
show_route_names_json |
false |
Include route names in JSON |
show_route_names_view |
false |
Show route names in HTML |
auto_redirect.enabled |
false |
Auto-redirect feature |
auto_redirect.threshold |
80 |
Similarity % needed for redirect |
auto_redirect.method |
session |
How to pass correction info |
auto_redirect.query_param |
route_corrected_from |
Query parameter name |
auto_redirect.session_key |
route_hints_correction |
Session key name |
Commands
php artisan route-hints:analyze [path] # Test route suggestions for any path php artisan route-hints:cache build # Build route cache for performance php artisan route-hints:cache status # Check cache status and info php artisan route-hints:cache clear # Clear route cache php artisan route-hints:setup-session # Configure auto-redirect session
Examples
| User Types | Gets Suggested | Why |
|---|---|---|
/user |
/users |
Typo correction |
/dashbord |
/dashboard |
Spelling mistake |
/home |
/dashboard |
Custom hint |
/product-categories |
/categories/electronics |
Parameterized with default |
Testing
The package includes a comprehensive test suite:
composer test
Laravel Version Compatibility
| Laravel Version | Package Version |
|---|---|
| 11.x | 1.x |
| 12.x | 1.x |
Security
If you discover any security issues, please email soliman.benhalim@gmail.com instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
sulimanbenhalim/route-hints 适用场景与选型建议
sulimanbenhalim/route-hints 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 08 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「routing」 「laravel」 「404」 「ux」 「suggestions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sulimanbenhalim/route-hints 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sulimanbenhalim/route-hints 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sulimanbenhalim/route-hints 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This module allows both simple and regular expression link redirections based on customisable mappings, either hooking into a page not found or replacing the default automated URL handling.
Wayne State University Error 404 HTTP Status
404 'not found' and 403 'forbidden' error handlers. The 404 handler shows custom content for missing pages but not resources like CSS or JS. The 403 handler redirects to a login URL on unauthorized access.
Write down your routing mapping at one place
Enables simple 404 Page NotFound handling, also for multilingual sites.
Flight routing is a simple, fast PHP router that is easy to get integrated with other routers.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-18