Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Path Util Laravel Package

webmozart/path-util

Lightweight PHP utility for safe, cross-platform path handling. Normalize, join, resolve and compare filesystem paths, with helpers for absolute/relative paths and canonicalization. Useful for file operations and libraries needing consistent path logic.

View on GitHub
Deep Wiki
Context7

A robust cross-platform utility for normalizing, comparing and modifying file paths.

Frequently asked questions about Path Util
Is webmozart/path-util safe to use in Laravel 10.x with PHP 8.1+?
No, the package hasn’t been updated since 2015 and may break on modern PHP due to changes in `realpath()` and type safety. You’ll need to fork it, update dependencies, or use alternatives like Symfony’s Filesystem component. Test thoroughly for cross-platform edge cases.
How do I normalize paths in Laravel using this package?
Use `Path::normalize()` to convert mixed separators (e.g., `C: ooar` → `/foo/bar`). For Laravel-specific paths, wrap it in a helper: `Path::normalize(storage_path('app/../logs'))`. Avoid hardcoding `DIRECTORY_SEPARATOR` for cross-platform consistency.
Does this package handle Windows long paths (>260 chars) or symlinks?
The original package lacks support for Windows long paths and may not fully resolve symlinks. For modern Laravel apps, consider Symfony’s Filesystem or a custom solution using `realpath()` with error handling for edge cases.
Can I use this instead of Laravel’s Storage facade for path handling?
No, this package complements—not replaces—Laravel’s Storage. Use it to pre-process paths before passing them to `Storage::put()` or `file_put_contents()`, especially for user uploads or CLI jobs where path consistency is critical.
What’s the performance impact of path normalization in bulk operations?
Path normalization is lightweight for single operations, but recursive tasks (e.g., scanning directories) could slow down. Benchmark against `str_replace()` + `DIRECTORY_SEPARATOR` for simple cases or Symfony’s Filesystem for optimized bulk handling.
Are there Laravel-specific forks or maintained alternatives?
Check for forks like `spatie/path-util` or use Symfony’s Filesystem (more modern but heavier). For minimal needs, Laravel’s `Str::of()` or `pathinfo()` may suffice, but this package offers path-specific logic like `isAbsolute()` or `getLongestCommonBasePath()`.
How do I test cross-platform path behavior in Laravel?
Use PHPUnit with Docker containers (Windows/Linux) or GitHub Actions. Mock `Path::normalize()` and test edge cases like `../` traversal, trailing slashes, and mixed separators. Avoid hardcoding paths in tests—use `Path::makeAbsolute()` with a base directory.
Will this work in Laravel’s filesystem drivers (e.g., S3, FTP)?
Yes, but only for local path normalization before uploads/downloads. For remote paths, ensure the driver’s SDK handles separators (e.g., AWS SDK v3 uses `/` consistently). This package won’t resolve remote paths—it’s for local filesystem consistency.
How do I migrate from hardcoded paths to this package?
Start by replacing `base_path()` or `storage_path()` calls with `Path::normalize()`. Use a regex to find hardcoded separators (e.g., `\\` or `/`). Test incrementally, focusing on non-critical paths first (e.g., logs, cache).
What’s the difference between this and Symfony’s Filesystem component?
This package is lighter (~20KB) and focuses solely on path logic (normalization, comparison). Symfony’s Filesystem (~100KB) adds filesystem operations (copy, move) and is actively maintained. Use Symfony if you need both path handling and filesystem tools.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity