https://github.com/sulimanbenhalim/route-hints
Laravel 404 errors → intelligent route suggestions
https://github.com/sulimanbenhalim/route-hints
404 laravel middleware package php routing suggestions ux
Last synced: 10 days ago
JSON representation
Laravel 404 errors → intelligent route suggestions
- Host: GitHub
- URL: https://github.com/sulimanbenhalim/route-hints
- Owner: sulimanbenhalim
- License: mit
- Created: 2025-08-18T11:50:08.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2025-08-22T12:15:08.000Z (5 months ago)
- Last Synced: 2025-09-21T10:15:34.957Z (4 months ago)
- Topics: 404, laravel, middleware, package, php, routing, suggestions, ux
- Language: PHP
- Size: 25.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# RouteHints Laravel Package
[](https://github.com/sulimanbenhalim/route-hints/blob/main/LICENSE.md)
[](https://www.php.net/supported-versions.php)
[](https://laravel.com/docs/11.x/releases)
> Laravel 404 errors → intelligent route suggestions
## Install
```bash
composer require sulimanbenhalim/route-hints
```
## Usage
### Routes Control
All routes discoverable by default
```php
Route::get('/users', UserController::class); // ✓ Suggested
Route::get('/posts', PostController::class)->discoverable(); // ✓ Explicitly suggested
Route::get('/admin', AdminController::class)->hidden(); // ✗ Never suggested
```
### Custom Keywords
```php
Route::get('/dashboard', HomeController::class)
->withHints(['home', 'control-panel']);
```
`/home` → suggests `/dashboard`
### Parameterized Routes
```php
Route::get('/posts/{post}', PostController::class)
->includeParameterized(['post' => 'welcome']);
```
`/post` → suggests `/posts/welcome`
### Programmatic Access
```php
$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`:
```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:**
```php
// 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
```bash
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
```bash
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:
```bash
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](LICENSE.md) for more information.