Weave 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

Basepath Laravel Package

selective/basepath

Selective Basepath lets Laravel routes use a different base path per request, so apps deployed in a subdirectory can still serve selected routes from the domain root. Middleware-driven configuration keeps URL generation, redirects, and assets correct without duplicating routes or rewriting config.

View on GitHub
Deep Wiki
Context7

Base path detector for Slim 4

Frequently asked questions about Basepath
How do I install selective/basepath in a Laravel application with Composer?
Run composer require selective/basepath, then confirm the tagged release and its PHP constraint match your runtime (8.2, 8.3 or 8.4) before committing the lockfile diff. Because it is a PSR-7 utility rather than a Laravel service provider package, there is nothing to auto-discover: you construct a PSR-7 request with nyholm/psr7 or guzzlehttp/psr7, run the detector, and push the resulting base path back into Laravel. Wire that once in a service provider or middleware instead of scattering it through controllers.
Does selective/basepath support Laravel 10, 11 and 12?
The library is framework-agnostic pure PHP and does not pin a Laravel version, so it can install alongside Laravel 10, 11 or 12 as long as the PHP constraint and PSR-7 implementation line up. Laravel 10, 11 and 12 pin Symfony HttpFoundation 6.x or 7.x, and a package this small is unlikely to create a transitive conflict, but run a dry-run install to confirm. Check the actual Packagist tag and PHP requirement rather than relying on repository metadata.
Is selective/basepath a Slim 4 package or a Laravel package?
It is fundamentally a PSR-7 utility built around Slim 4's request and middleware pipeline, even when described as a Laravel base path helper. Laravel's HTTP layer is Symfony HttpFoundation, and Illuminate Http Request is not PSR-7, so there is no natural insertion point in a Laravel request lifecycle. In Laravel you would have to build a PSR-7 request, run the detection, then convert the result back through URL forceRootUrl, a config value or a request attribute.
How does selective/basepath differ from URL::forceRootUrl() and Request::getBasePath()?
Symfony's Request already exposes getBasePath, getBaseUrl and getSchemeAndHttpHost, and Laravel layers url, asset, route and TrustProxies on top, so most subdirectory problems are solved natively. URL forceRootUrl sets the root used for URL generation, which is usually all a Laravel application needs. selective/basepath only adds value when the identical detection logic must be shared with a non-Laravel service.
Can selective/basepath serve selected routes from the domain root while the app lives in a subdirectory?
That is the intended middleware-driven scenario: the base path is resolved per request so selected routes are served from the domain root while the application itself sits in a subdirectory, keeping URL generation, redirects and assets correct. In a Laravel app you implement the same behaviour with a small middleware that calls URL forceRootUrl or sets a request attribute, rather than duplicating route definitions or rewriting configuration. Reserve the package itself for cases where a Slim service shares the requirement.
Does selective/basepath work behind an ALB, nginx or Cloudflare?
Its detection relies on parsing SCRIPT_NAME and REQUEST_URI, so if your edge rewrites those values the detected base path may not match what clients actually see. A proxy that rewrites SCRIPT_NAME is a TrustProxies and forceRootUrl problem, not a base path detection problem. Verify the exact headers your load balancer or CDN emits before trusting the result.
How do I test base path detection with selective/basepath?
Unit test the detector with crafted PSR-7 requests whose SCRIPT_NAME and REQUEST_URI cover subdirectory, domain-root and proxy-rewritten cases. In Laravel, add feature tests that assert route and url output under both a subdirectory mount and a forced root URL. Keep detection behind an interface so tests can swap in a fake resolver.
What are the risks of adding selective/basepath to a Laravel monolith?
The absolute technical risk is low: the library is small, pure PHP, MIT licensed and needs no native extensions. The relational risk is higher, with roughly 48 stars and no dependents meaning almost no independent production validation, plus a single maintainer to weigh for bus factor. Since equivalent logic is around 200 lines, vendoring it or writing a 30-line resolver over getBasePath is a reasonable alternative.
How do I avoid a psr/http-message v1 versus v2 conflict with selective/basepath?
Check which psr/http-message major version the package requires and match it against your PSR-7 implementation, whether that is nyholm/psr7 or guzzlehttp/psr7. A composer require dry run, or composer why-not, will surface a split before it reaches production. Version splits in psr/http-message are a common failure point in single-maintainer libraries, so pin deliberately.
What are the Laravel-native alternatives to selective/basepath for subdirectory deployments?
Use Symfony's Request getBasePath and getBaseUrl, resolve once with URL forceRootUrl in a service provider, configure TrustProxies for rewritten headers, and prefix route groups where needed. For a Laravel-only estate, treat selective/basepath as a reference implementation to copy rather than a Composer requirement. Adopt it only when a Slim or other PSR-7 service must agree on the same base path.
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.
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource