spatie/url), which aligns well with modern Laravel architectures (e.g., DTOs, Data objects, or domain-driven design). This reduces mutable state and enforces type safety for URLs across the application.Referer, Origin headers).chrome-extension://, mailto:, or data: fills a niche where Laravel’s built-in URL handling (e.g., Str::of(), Url::to()) lacks robustness.spatie/laravel-data enables seamless casting of URLs in Data objects, reducing boilerplate in API responses or form requests.Key Fit Areas:
mailto: handlers) in middleware or services.spatie/url (v3.x+), which is stable and widely adopted.spatie/laravel-data (if using Data objects).Feasibility Risks:
spatie/url’s roadmap. Monitor for breaking changes in spatie/url v4+.web+npm:).| Risk Area | Severity | Mitigation |
|---|---|---|
| Unproven Codebase | Medium | Low stars/dependents suggest limited adoption; review tests and CI coverage. |
Dependency on spatie/url |
Medium | Monitor spatie/url for deprecations; consider forking if critical changes occur. |
| Browser Scheme Quirks | Low | Test with real-world schemes (e.g., chrome-extension://, data:) in staging. |
| Performance Overhead | Low | Sanitization pipelines add minimal overhead; benchmark if processing high-volume URLs. |
| Laravel Version Lock | Low | Package targets Laravel 10+; ensure compatibility if using older versions. |
Key Questions for TPM:
spatie/url alone suffice, or does Laravel-specific integration justify this package?spatie/url for breaking changes?Referer, Origin, or Location headers in middleware.Url objects).Stack Compatibility:
| Component | Compatibility | Notes |
|---|---|---|
| Laravel Validation | High | Built-in validation rules (Url, UrlSanitized). |
| Form Requests | High | Macros for Url casting. |
| Laravel Data | High | Optional but seamless integration. |
| Middleware | Medium | Useful for header parsing (e.g., Referer). |
| Queue Jobs | Low | Not a primary use case. |
| Livewire/Inertia | Medium | Could sanitize URLs in frontend-backend sync. |
Phase 1: Core URL Handling
Url value objects in models, DTOs, and services.use Atldays\Url\Url;
// Before
$redirectUrl = request()->input('redirect_url');
// After
$redirectUrl = Url::fromString(request()->input('redirect_url'));
str()/url() helpers with Url::.Phase 2: Validation/Sanitization
use Atldays\Url\Rules\UrlSanitized;
public function rules(): array
{
return [
'redirect_url' => ['required', new UrlSanitized],
];
}
use Atldays\Url\Sanitizers\Pipeline;
$referer = Pipeline::sanitize(request()->header('Referer'));
Phase 3: Advanced Features
use Atldays\Url\Casts\Url as UrlCast;
class LinkData extends Data
{
public function url(): Url
{
return $this->cast(UrlCast::class);
}
}
chrome-extension://).spatie/url updates.Url object behavior (e.g., parsing, sanitization).data:, mailto:) and malformed input.| Priority | Task | Dependencies |
|---|---|---|
| High | Replace raw URL strings with Url objects |
None |
| Medium | Add validation rules to Form Requests | Core Url integration |
| Medium | Sanitize headers in middleware | Pipeline configuration |
| Low | Integrate with Laravel Data | Data objects in use |
| Low | Extend for browser-specific schemes | Business need for extension links, etc. |
Rollout Strategy:
spatie/url updates.Maintenance Tasks:
spatie/url updates.Url::fromRequest('redirect')).How can I help you explore Laravel packages today?