rayzenai/url-manager
Laravel package to manage URLs, redirects, SEO metadata, visit tracking, and XML sitemaps, with redirect-loop protection and automatic old→new slug redirects. Includes Filament 4 admin panel integration (UrlInput) and optional media SEO via file-manager.
The URL Manager package now supports automatic view count tracking for models that use the HasUrl trait.
When a URL is visited, the RecordUrlVisit job is dispatched which:
getViewCountColumn() methodTo enable view count tracking for your model:
Schema::table('your_table', function (Blueprint $table) {
$table->integer('view_count')->default(0);
});
getViewCountColumn() method in your modelclass Entity extends Model
{
use \RayzenAI\UrlManager\Traits\HasUrl;
/**
* Get the view count column name for URL visit tracking
*/
public function getViewCountColumn(): ?string
{
return 'view_count'; // Return the column name
}
}
If your model doesn't track view counts, return null:
public function getViewCountColumn(): ?string
{
return null; // No view count tracking
}
This approach avoids expensive Schema::hasColumn() checks on every request by using a simple method check instead. Models explicitly declare their view count column, making the system more efficient and predictable.
For more advanced tracking needs, you can also implement a recordVisit() method in your model:
public function recordVisit(?int $userId, array $metadata = []): void
{
// Custom visit tracking logic
// e.g., track unique visitors, geographic data, etc.
}
This method will be called automatically by the RecordUrlVisit job if it exists on your model.
How can I help you explore Laravel packages today?