Download the PHP package rayzenai/url-manager without Composer
On this page you can find all versions of the php package rayzenai/url-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package url-manager
RayzenAI URL Manager
A comprehensive Laravel package for managing URLs, redirects, and sitemaps with Filament admin panel integration.
Features
- ๐ Dynamic URL Management - Manage all your application URLs from a central location
- ๐ 301/302 Redirects - Create and manage URL redirects with configurable status codes
- ๐ Automatic Redirect Creation - Update slugs safely with automatic oldโnew redirects
- ๐บ๏ธ Automatic Sitemap Generation - Generate XML sitemaps with support for large sites
- ๐ Visit Tracking - Track URL visits with country detection, device info, and mobile app support
- ๐จ Filament Integration - Full-featured admin panel with UrlInput form component
- ๐ท๏ธ SEO Metadata - Manage meta tags and Open Graph data
- ๐ Performance Optimized - Efficient database queries with proper indexing
- ๐ Redirect Loop Protection - Automatic detection and prevention of circular redirects (AโBโA, AโBโCโA)
Requirements
- PHP 8.2+
- Laravel 11.0+ or 12.0+
- Filament 4.0+
- Stevebauman/Location 7.0+ with MaxMind database (for visitor country detection)
- kirantimsina/file-manager (optional, for media SEO functionality)
Installation
Step 1: Install via Composer
Optional: Install File Manager for Enhanced SEO
For complete media SEO functionality, install the companion file-manager package:
This package provides:
- Media metadata tracking with SEO titles
- Image optimization and compression
- Enhanced file upload components for Filament
Step 2: Publish Configuration
Step 3: Configure Location Service (Required for visitor tracking)
The URL Manager uses the Stevebauman/Location package to detect visitor countries from IP addresses. You need to set up MaxMind's GeoIP database:
Option A: Use Local Database (Recommended)
- Download the free GeoLite2 City database from MaxMind
- Create a free account and download
GeoLite2-City.mmdb - Place the file in your Laravel project:
database/maxmind/GeoLite2-City.mmdb -
Publish and configure the Location package:
- Update
config/location.php:
Option B: Use Web Service
Configure MaxMind web service in your .env:
Step 4: Run Migrations
This will create the following tables:
urls- For managing URLs and redirectsurl_visits- For tracking visitor analyticsgoogle_search_console_settings- For storing Google Search Console credentials securely
Step 5: Register with Filament
Add the plugin to your Filament panel configuration (typically in app/Providers/Filament/AdminPanelProvider.php):
Step 5: Configure Your Models
Add the HasUrl trait to any model that needs URL management:
Step 6: Register Redirect Middleware
To enable automatic redirect handling when slugs are updated, add the middleware to your bootstrap/app.php:
Why prepend? The middleware must run BEFORE route model binding. If you have a route like /leader/{leader:slug} and someone visits /leader/old-slug, the middleware catches it and redirects to /leader/new-slug before Laravel tries (and fails) to find a model with slug='old-slug'.
What it does:
- โ Checks if the current URL path is a redirect in the database
- โ Performs 301/302 redirects automatically
- โ
Preserves query strings (
?page=2) - โ Only checks GET requests (no overhead on POST/PUT/DELETE)
- โ Prevents 404 errors for updated slugs
Usage
Checking Your Configuration
Before you start using URL Manager, check that all your models are properly configured:
This command will verify:
- โ
webUrlPath()method is implemented - โ
is_active(or custom active field) exists in database - โ
getViewCountColumn()is configured correctly - โ
SEO methods (
ogTags(),getSeoMetadata()) are present - โ URL records have been generated
- โ ๏ธ Warnings for optional but recommended features
Creating New Models with HasUrl
Generate a new model with HasUrl trait and all required methods pre-configured:
The generated model includes:
- HasUrl trait already configured
webUrlPath()method with sensible defaultsgetViewCountColumn()for automatic view trackingogTags()andgetSeoMetadata()for SEO- Proper fillable fields and casts
Using the UrlManager Facade
For common URL operations, use the UrlManager facade:
Creating URLs for Existing Models
Generate URLs for all models that use the HasUrl trait:
Or for a specific model:
Handling Large Datasets
For large datasets with thousands of records, you may need to increase PHP memory and execution limits:
Creating Redirects
Via Filament Admin
- Navigate to the URLs section in your Filament admin panel
- Click "Create Redirect"
- Enter the source and destination URLs
- Choose redirect type (301 or 302)
Programmatically
Generating Sitemaps
Generate a sitemap with all active URLs:
For large sites (>10,000 URLs), the package automatically creates multiple sitemap files with an index.
Including Custom Static Routes
You can include static routes in your sitemap that aren't tied to database models. This is useful for:
- Static pages (About, Contact, Terms of Service)
- Custom Livewire components
- API documentation pages
- Any route that should appear in your sitemap but doesn't use the HasUrl trait
Configure custom routes in config/url-manager.php:
Available Options:
path(required): The route path (e.g.,/about,/contact)priority(optional): SEO priority from 0.0 to 1.0 (default: 0.5)changefreq(optional): How often the page changes:always,hourly,daily,weekly,monthly,yearly,never(default:weekly)lastmod(optional): Last modification date as Carbon instance or date string (default: current time)
These routes will be automatically included when you run:
Submitting Sitemaps to Search Engines
Since Google deprecated the ping endpoint in June 2023 and Bing has also discontinued their ping service, API credentials are now required for automated sitemap submission.
Setting up Google Search Console API
Prerequisites:
- A verified property in Google Search Console
- A Google Cloud Project with billing enabled (API has free tier)
Using Service Account Authentication
-
Create a Google Cloud Project:
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable these APIs:
- "Google Search Console API"
- "Search Console API" (if available)
- Note: The "Indexing API" is separate and not needed for sitemap submission
-
Create a Service Account:
- Navigate to "IAM & Admin" > "Service Accounts"
- Click "Create Service Account"
- Give it a name like "sitemap-submitter"
- Click "Create and Continue"
- Skip the optional role assignment (click "Continue")
- Click "Done"
- Find your new service account in the list and click on it
- Go to the "Keys" tab
- Click "Add Key" > "Create New Key"
- Select "JSON" format
- Click "Create" to download the JSON credentials file
- Keep this file secure - it contains credentials for API access
-
Add Service Account to Search Console:
- Go to Google Search Console
- Select your property
- Go to Settings > Users and permissions
- Click "Add user"
- Enter the service account email (found in the JSON file, looks like
[email protected]) - Select "Owner" permission level
- Click "Add"
-
Configure in Admin Panel:
- Navigate to the Google Search Console settings page in your Filament admin panel
- Toggle "Enable Google Search Console Integration" to ON
- Enter your site URL or domain property:
- For URL-prefix property:
https://www.yoursite.com(must match exactly) - For Domain property:
sc-domain:yoursite.com(recommended - covers all subdomains and protocols)
- For URL-prefix property:
- Add your Service Account credentials:
- Open your downloaded JSON file in a text editor
- Copy the entire JSON content
- Paste it into the "Service Account JSON" field
- The service account email will be automatically extracted
- Click "Save Settings"
- Use "Test Connection" to verify the setup is working
Why Database Storage?
- Credentials are encrypted and stored securely in your database
- Survives deployments (no need to re-upload files)
- No file system dependencies
- Easier to manage in production environments
Submitting Sitemaps
Once configured, you can submit sitemaps in multiple ways:
-
Via Admin Panel:
- Go to URLs management page in Filament
- Click "Submit to Search Engines" button
-
Via Command Line:
- Programmatically:
Troubleshooting Google Search Console
Service Account Issues:
- "API not configured" error: Ensure you've enabled the Google Search Console API in your Google Cloud Project
- "Site not verified" error: Make sure the service account email is added as a user in Search Console with "Owner" permissions
- "Invalid credentials" error: Check that the JSON file path is correct and the file is readable by the web server
- 403 Forbidden errors:
- The service account may not have proper permissions. Verify it's added to Search Console with "Owner" role
- Check if you're using the correct property format. If you have a domain property in Search Console, use
sc-domain:yoursite.comformat - Verify the exact property format in Search Console matches what you've configured
- Invalid JSON error: Ensure you're copying the complete JSON content from the credentials file, including all brackets
General Issues:
- "Invalid site URL" error: The site URL must match exactly with how it's registered in Search Console (including www/non-www, https/http)
- No sitemaps found: The site may not have any sitemaps submitted yet. Use "Submit Sitemap Now" button to submit
- Rate limiting: Google Search Console API has quotas. Check your Google Cloud Console for usage limits
- Connection test passes but submission fails: Check that sitemap.xml exists and is accessible at the expected URL
Note on Bing
Bing has also discontinued their ping endpoint. Sitemaps must be manually submitted through Bing Webmaster Tools.
Accessing URLs in Your Application
Visit Tracking
The package automatically tracks URL visits, but to track view counts on your models, you need to implement the getViewCountColumn() method:
Important: Make sure your database migration includes the view count column:
The package provides two ways to track visits:
Method 1: Using Middleware (Recommended for Livewire & API Routes)
Register the middleware in your application:
For Laravel 11 - Add to bootstrap/app.php:
For Laravel 10 and below - Add to app/Http/Kernel.php:
Then apply the middleware to your routes:
The middleware automatically:
- Matches the request path against URLs in the database
- Records visits asynchronously via queued jobs
- Captures IP address, user agent, referrer, and authenticated user ID
- Increments the model's view_count if
getViewCountColumn()is implemented - Works transparently without modifying your controllers or components
Method 2: Using Fallback Route
If you use the package's fallback route controller:
Visits are automatically tracked for any URL managed by the package.
Accessing Visit Data
Note: The difference between URL visits and model view counts:
- URL visits: Tracked in the
urlstable andurl_visitstable (always enabled) - Model view counts: Tracked on your model's
view_countcolumn (requiresgetViewCountColumn()implementation)
Visitor Analytics Features
The URL Manager provides comprehensive visitor tracking with the following features:
Country Detection
- Automatically detects visitor's country from IP address using MaxMind GeoIP database
- Displays country flags (๐บ๐ธ ๐ฌ๐ง ๐ณ๐ต ๐ฎ๐ณ) in the admin panel
- Filter visits by country in Filament resource
Mobile App Detection
The package intelligently detects mobile app traffic through:
- API Source Parameters: Recognizes
source=androidorsource=iosparameters - User-Agent Analysis: Detects Flutter, React Native, Expo, and other mobile frameworks
- HTTP Client Detection: Identifies OkHttp (Android) and Alamofire (iOS) clients
Populate Existing Data
If you have existing visitor data without country codes, run:
This command will:
- Process all URL visits without country codes
- Resolve countries from IP addresses
- Update records with detected country codes
Visitor Information Tracked
- IP Address with country flag
- Country Code with flag emoji display
- Browser/App type and version
- Device Type (Desktop, Mobile, Tablet)
- Referrer URL
- User (if authenticated)
- Visit Timestamp
- Metadata (additional custom data)
Testing Referrer Tracking
The package includes a built-in test page to verify that referrer tracking is working correctly. This is especially useful when setting up the package or debugging referrer capture issues.
Access the test page (only available in non-production environments):
The test page provides:
- A visual interface to add and visit entity URLs
- Automatic referrer capture via JavaScript (works even when browsers block HTTP Referer headers)
- Real-time verification of referrer tracking
- Instructions for checking captured referrers in Filament admin panel
How it works:
- Visit the test page at
/_url-manager/test - Add your entity slugs (e.g.,
entities/my-product,blog/my-post) - Click on the links to visit those pages
- Check Filament admin panel โ URL Visits โ Toggle "Referrer" column
- You should see the test page URL as the referrer
The test page uses a multi-layer approach to ensure referrers are captured:
- JavaScript-based capture (passes referrer as
?ref=query parameter) - HTTP Referer header support
- Multiple fallback sources (headers and server variables)
Note: The test route is automatically disabled in production environments for security.
Configuration
The configuration file config/url-manager.php allows you to customize:
Advanced Features
UrlManager Facade
The UrlManager facade provides a convenient API for common URL operations:
When to use the facade:
- Creating redirects programmatically
- Manual visit tracking (in addition to automatic tracking)
- Quick URL lookups by slug
- Debugging or admin tools
When NOT to use it:
- URL creation is automatic via HasUrl trait events
- Visit tracking is automatic via middleware/fallback route
- Use the facade only when you need programmatic control
Custom URL Types
Register custom URL types in your configuration:
SEO Metadata
Models can provide SEO metadata through the getSeoMetadata() method:
Event Handling
Listen for URL events in your application:
Media SEO with File Manager
If you have the kirantimsina/file-manager package installed, you can enhance your SEO by managing media metadata:
Populate SEO Titles for Images
Generate SEO-friendly titles for all your media files:
The command automatically generates SEO-friendly titles based on:
- Parent model's name/title
- Media field context (e.g., "Featured Image", "Gallery")
- Clean filename processing
- Removes special characters from beginning/end for cleaner SEO
Image Sitemap Generation
Generate a dedicated image sitemap for better image SEO:
Features:
- Uses pre-populated SEO titles from media_metadata table for optimal performance
- Only includes images with meaningful SEO titles (excludes internal/system images)
- Automatically creates index files for large image collections
- Generates Google Image sitemap format with proper XML namespace
- Includes image location, title, and caption metadata
- Uses optimized image sizes instead of originals for better performance
Performance Optimization:
- Direct database queries avoid expensive polymorphic lookups
- Chunked processing for handling millions of images
- Only processes images from SEO-enabled models (configured in file-manager)
Image Size Configuration
Configure the image size used in sitemaps in config/url-manager.php:
The available sizes are defined in your config/file-manager.php:
SEO Title Configuration
Control which models receive SEO titles in config/file-manager.php:
Media Metadata in Sitemaps
When using file-manager, media files are automatically included in your sitemaps with proper SEO titles and metadata for better search engine indexing. The integration:
- Respects model configuration (enabled/excluded models)
- Uses cached SEO titles for fast generation
- Supports large-scale image collections with automatic file splitting
Multiple Sitemap Support
For sites with more than 10,000 URLs, the package automatically generates multiple sitemap files:
Filament Admin Panel
The package includes a complete Filament resource with:
- URL Listing - Search, filter, and sort URLs
- Create/Edit Forms - Manage URL details and metadata
- Redirect Creation - Quick action to create 301/302 redirects
- Sitemap Generation - Generate and view sitemaps
- Bulk Actions - Activate/deactivate multiple URLs
- Visit Statistics - View visit counts and last visited times
Dashboard Widgets
The package provides two dashboard widgets:
- URL Stats Overview - Displays total URLs, redirects, and visit statistics
- Top URLs Table - Shows the 10 most visited URLs with their metrics
Filament Form Components
UrlInput Component
The package provides a UrlInput form component for managing slugs in Filament forms:
Allowing Slug Updates:
By default, slugs are disabled when editing records to prevent breaking existing URLs. To allow updates (with automatic redirect creation):
How it works:
- โ When you update a slug, the old URL is automatically converted to a redirect
- โ Circular redirect chains are detected and prevented (AโBโA)
- โ Throws exception if circular chain would be created
- โ
Works seamlessly with the
HasUrltrait
Example:
- Leader has slug
kp-oliwith URL/leader/kp-oli - Admin updates slug to
kp-sharma-oliin Filament - Database now has:
- Active URL:
/leader/kp-sharma-oli(points to leader) - Redirect:
/leader/kp-oliโ/leader/kp-sharma-oli
- Active URL:
- Users visiting old URL are automatically redirected
Best Practices
- Always include an active field (
is_activeoractive) in models using HasUrl trait - Include a slug field in models using HasUrl trait (override via
slugField()if using different name) - Implement
webUrlPath()method to define URL structure - Override
activeUrlField()method if using a field name other thanis_active - Use meaningful slugs for SEO optimization
- Allow slug updates safely - Use
UrlInput::make('slug')->allowUpdatingSlug()for automatic redirect creation - Generate sitemaps regularly (via cron job)
- Circular redirects are prevented automatically - The package detects and blocks AโBโA or AโBโCโA chains
- Use appropriate HTTP status codes (301 for permanent, 302 for temporary)
Testing
Run the package tests:
Troubleshooting
URLs not generating for models
Ensure your model:
- Uses the
HasUrltrait - Has an active field (
is_activeoractive- configurable viaactiveUrlField()method) - Implements the
webUrlPath()method
Common URL Generation Issues
-
"URL with slug already exists for different model" Warning
- This occurs when multiple models have the same slug
- Solution: Ensure unique slugs within each model type
- The command skips duplicates to maintain data integrity
-
Not all URLs are generated
- Check for duplicate slugs in your data
- Verify models have unique slug values
- For large datasets, increase PHP memory limit
- Run the command multiple times if needed
- Models using 'active' instead of 'is_active'
- Override the
activeUrlField()method in your model:
- Override the
Sitemap not accessible
Check that:
- Sitemap generation is enabled in config
- The public directory is writable
- Routes are properly registered
Redirects not working
Verify:
- The
HandleUrlRedirectsmiddleware is registered withprepend(notappend) inbootstrap/app.php - Middleware runs BEFORE route model binding
- Redirect depth limit hasn't been exceeded (check
url-manager.max_redirect_depthconfig) - Check for circular redirect chains in the database
Contributing
Contributions are welcome! Please submit pull requests with tests.
License
MIT License. See LICENSE file for details.
Support
For issues and questions, please use the GitHub issue tracker.
Credits
Created by Kiran Timsina at RayzenAI.
All versions of url-manager with dependencies
illuminate/support Version ^11.0||^12.0||^13.0
filament/filament Version ^5.0
spatie/laravel-package-tools Version ^1.16
spatie/laravel-sitemap Version ^7.0
google/apiclient Version ^2.0
jenssegers/agent Version ^2.6
laravel/sanctum Version ^4.0
stevebauman/location Version ^7.0